Module: Elastics::ActiveRecord
- Extended by:
- ActiveSupport::Autoload
- 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,
lib/elastics/active_record/instrumentation.rb
Defined Under Namespace
Modules: HelperMethods, Instrumentation, LogSubscriber, ModelSchema, TasksConfig
Classes: SearchResult
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.install ⇒ Object
12
13
14
15
|
# File 'lib/elastics/active_record.rb', line 12
def install
::ActiveRecord::Base.extend self
Instrumentation.install
end
|
Instance Method Details
#elastics ⇒ Object
23
24
25
|
# File 'lib/elastics/active_record.rb', line 23
def elastics
@elastics ||= Client.new elastics_config.slice(:host, :port)
end
|
#elastics_config ⇒ Object
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
|
#elastics_version_manager ⇒ Object
Don’t memoize to GC it after initialization
28
29
30
31
32
33
|
# File 'lib/elastics/active_record.rb', line 28
def elastics_version_manager
VersionManager.new(elastics, elastics_config.slice(
:service_index,
:index_prefix,
))
end
|
#indexed_with_elastics(options = {}) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/elastics/active_record.rb', line 35
def indexed_with_elastics(options = {})
options = {
hooks: [:update, :destroy],
}.merge!(options)
extend ModelSchema
include HelperMethods
self.elastics_index_base = options[:index] if options[:index]
self.elastics_type_name = options[:type] if options[:type]
hooks = options[:hooks]
after_commit :index_elastics, on: [:create, :update] if hooks.include?(:update)
after_commit :delete_elastics, on: [:destroy] if hooks.include?(:destroy)
end
|