Commit ea4cc798f5ab2941e90472e7b644c19067fde2a7

Authored by Andrew Kane
1 parent 4c3ad926

Fixed reindex method when callbacks disabled - closes #120

Showing 1 changed file with 7 additions and 9 deletions   Show diff stats
lib/searchkick/model.rb
... ... @@ -19,8 +19,8 @@ module Searchkick
19 19 extend Searchkick::Reindex
20 20 include Searchkick::Similar
21 21  
22   - after_save :reindex
23   - after_destroy :reindex
  22 + after_save :reindex, if: proc { self.class.search_callbacks? }
  23 + after_destroy :reindex, if: proc { self.class.search_callbacks? }
24 24  
25 25 def self.enable_search_callbacks
26 26 class_variable_set :@@searchkick_callbacks, true
... ... @@ -39,13 +39,11 @@ module Searchkick
39 39 end
40 40  
41 41 def reindex
42   - if self.class.search_callbacks?
43   - index = self.class.searchkick_index
44   - if destroyed? or !should_index?
45   - index.remove self
46   - else
47   - index.store self
48   - end
  42 + index = self.class.searchkick_index
  43 + if destroyed? or !should_index?
  44 + index.remove self
  45 + else
  46 + index.store self
49 47 end
50 48 end
51 49  
... ...