Module: Asari::ActiveRecord

Defined in:
lib/asari/active_record.rb

Overview

Public: This module should be included in any class inheriting from ActiveRecord::Base that needs to be indexed. Every time this module is included, asari_index must be called (see below). Including this module will automatically create before_destroy, after_create, and after_update AR callbacks to remove, add, and update items in the CloudSearch index (respectively).

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/asari/active_record.rb', line 10

def self.included(base)
  base.extend(ClassMethods)

  base.class_eval do
    before_destroy :asari_remove_from_index
    after_create :asari_add_to_index
    after_update :asari_update_in_index
  end
end

Instance Method Details

#asari_add_to_indexObject



24
25
26
# File 'lib/asari/active_record.rb', line 24

def asari_add_to_index
  self.class.asari_add_item(self)
end

#asari_remove_from_indexObject



20
21
22
# File 'lib/asari/active_record.rb', line 20

def asari_remove_from_index
  self.class.asari_remove_item(self)
end

#asari_update_in_indexObject



28
29
30
# File 'lib/asari/active_record.rb', line 28

def asari_update_in_index
  self.class.asari_update_item(self)
end