Module: ElasticSearch::Model::ClassMethods

Defined in:
lib/elastic_search/model.rb

Instance Method Summary collapse

Instance Method Details

#notifies_index(index) ⇒ Object

Notifies the index on after_save and after_destroy callbacks, such that the index can re-index/delete the respective records. Works with all ORMs supporting after_save and after_destroy callbacks, like eg. ActiveRecord, Mongoid, etc.

Examples:

class User < ActiveRecord::Base
  include ElasticSearch::Model

  notifies_index UserIndex

  # ... is equivalent to:

  # after_save { |user| UserIndex.import(user) }
  # after_destroy { |user| UserIndex.delete(user) }
end


31
32
33
34
# File 'lib/elastic_search/model.rb', line 31

def notifies_index(index)
  after_save { |record| index.import(record) }
  after_destroy { |record| index.delete(record) }
end