Main module containing the infrastructure for automatic updating of the Elasticsearch index on model instance create, update or delete.
Include it in your model: `include Tire::Model::Callbacks`
The model must respond to `after_save` and `after_destroy` callbacks (ActiveModel and ActiveRecord models do so, by default).
A hook triggered by the `include Tire::Model::Callbacks` statement in the model.
# File lib/tire/model/callbacks.rb, line 16 def self.included(base) # Update index on model instance change or destroy. # if base.respond_to?(:after_save) && base.respond_to?(:after_destroy) base.send :after_save, lambda { tire.update_index } base.send :after_destroy, lambda { tire.update_index } end # Add neccessary infrastructure for the model, when missing in # some half-baked ActiveModel implementations. # if base.respond_to?(:before_destroy) && !base.instance_methods.map(&:to_sym).include?(:destroyed?) base.class_eval do before_destroy { @destroyed = true } def destroyed?; !!@destroyed; end end end end
# File lib/tire/model/callbacks.rb, line 31 def destroyed?; !!@destroyed; end