Module: Elastics::ActiveRecord

Extended by:
ActiveSupport::Autoload
Includes:
Model::Connection
Defined in:
lib/elastics/active_record.rb,
lib/elastics/active_record/model_schema.rb,
lib/elastics/active_record/tasks_config.rb,
lib/elastics/active_record/search_result.rb,
lib/elastics/active_record/helper_methods.rb

Defined Under Namespace

Modules: HelperMethods, ModelSchema, TasksConfig Classes: SearchResult

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model::Connection

#elastics, #elastics_version_manager

Class Method Details

.installObject



10
11
12
13
# File 'lib/elastics/active_record.rb', line 10

def install
  ::ActiveRecord::Base.extend self
  Instrumentation::ActiveSupport.install
end

Instance Method Details

#elastics_configObject



18
19
20
21
# File 'lib/elastics/active_record.rb', line 18

def elastics_config
  @elastics_config ||= connection_config[:elastics].try!(:with_indifferent_access) ||
    raise('No elastics configuration in database.yml')
end

#indexed_with_elastics(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/elastics/active_record.rb', line 23

def indexed_with_elastics(options = {})
  options = {
    hooks: [:update, :destroy],
  }.merge!(options)

  extend ModelSchema
  include HelperMethods
  extend Model::Tracking

  self.elastics_index_base  = options[:index] if options[:index]
  self.elastics_type_name   = options[:type]  if options[:type]

  install_elastics_hooks(options[:hooks])
end