Class: Xapit::Client::ActiveRecordAdapter

Inherits:
AbstractModelAdapter show all
Defined in:
lib/xapit/client/model_adapters/active_record_adapter.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractModelAdapter

adapter_class, inherited, #initialize

Constructor Details

This class inherits a constructor from Xapit::Client::AbstractModelAdapter

Class Method Details

.for_class?(model_class) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/xapit/client/model_adapters/active_record_adapter.rb', line 4

def self.for_class?(model_class)
  model_class <= ActiveRecord::Base
end

Instance Method Details

#index_allObject



20
21
22
23
24
# File 'lib/xapit/client/model_adapters/active_record_adapter.rb', line 20

def index_all
  @model_class.find_each do |member|
    member.class.xapit_index_builder.add_document(member)
  end
end

#setupObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/xapit/client/model_adapters/active_record_adapter.rb', line 8

def setup
  @model_class.after_create do |member|
    member.class.xapit_index_builder.add_document(member) if Xapit.config[:enabled]
  end
  @model_class.after_update do |member|
    member.class.xapit_index_builder.update_document(member) if Xapit.config[:enabled]
  end
  @model_class.after_destroy do |member|
    member.class.xapit_index_builder.remove_document(member) if Xapit.config[:enabled]
  end
end