lib/mongoid/elasticsearch/callbacks.rb in mongoid-elasticsearch-0.7.0 vs lib/mongoid/elasticsearch/callbacks.rb in mongoid-elasticsearch-0.8.0

- old
+ new

@@ -2,16 +2,29 @@ module Elasticsearch module Callbacks extend ActiveSupport::Concern included do - after_save do + after_save :update_es_index + after_destroy :update_es_index + + def update_es_index es_update end + end - after_destroy do - es_update - end + module ClassMethods + def without_es_update!( &block ) + skip_callback( :save, :after, :update_es_index ) + skip_callback( :destroy, :after, :update_es_index ) + + result = yield + + set_callback( :save, :after, :update_es_index ) + set_callback( :destroy, :after, :update_es_index ) + + result + end end end end end