Module: Elastify::ActiveRecordExtensions::ClassMethods

Extended by:
ActiveSupport::Concern
Defined in:
lib/elastify/active_record_extensions.rb

Instance Method Summary collapse

Instance Method Details

#elastify_model(model_name) {|model| ... } ⇒ Object

Yields:

  • (model)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/elastify/active_record_extensions.rb', line 11

def elastify_model(model_name)
    include Elastify::ActiveRecordExtensions::LocalMethods
    cattr_accessor :elastify_options
    attr_accessor :elastify_serialized_document

    model = Elastify.models[model_name.to_sym]
    yield(model) if block_given?
    self.elastify_options = {} if self.elastify_options.blank?
    self.elastify_options[:base_url] = Elastify.configs.base_url
    self.elastify_options[:index] = model.opt_index if model.opt_index.present?
    self.elastify_options[:type] = model.opt_type if model.opt_type.present?
    self.elastify_options[:map] = model.opt_mapping if model.opt_mapping.present?
    self.elastify_options[:decode] = model.opt_decode if model.opt_decode.present?
    self.elastify_options[:encode] = model.opt_encode if model.opt_encode.present?
    self.elastify_options[:scroll_timeout] = model.opt_scroll_timeout if model.opt_scroll_timeout.present?
end

#elastify_scroll(scroll_id: nil, scroll_timeout: nil) ⇒ Object



49
50
51
# File 'lib/elastify/active_record_extensions.rb', line 49

def elastify_scroll(scroll_id: nil, scroll_timeout: nil)
    Elastify::Helpers::ElasticSearch::Document.new(self.elastify_options).scroll(scroll_id, scroll_timeout)
end

#elastify_search(dsl: nil, scroll_timeout: nil) ⇒ Object



45
46
47
# File 'lib/elastify/active_record_extensions.rb', line 45

def elastify_search(dsl: nil, scroll_timeout: nil)
    Elastify::Helpers::ElasticSearch::Document.new(self.elastify_options).search(dsl, scroll_timeout)
end

#elastify_setup {|model| ... } ⇒ Object

Yields:

  • (model)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/elastify/active_record_extensions.rb', line 28

def elastify_setup
    include Elastify::ActiveRecordExtensions::LocalMethods
    cattr_accessor :elastify_options
    attr_accessor :elastify_serialized_document

    model = Elastify::Model.new
    yield(model) if block_given?
    self.elastify_options = {} if self.elastify_options.blank?
    self.elastify_options[:base_url] = Elastify.configs.base_url
    self.elastify_options[:index] = model.opt_index if model.opt_index.present?
    self.elastify_options[:type] = model.opt_type if model.opt_type.present?
    self.elastify_options[:map] = model.opt_mapping if model.opt_mapping.present?
    self.elastify_options[:decode] = model.opt_decode if model.opt_decode.present?
    self.elastify_options[:encode] = model.opt_encode if model.opt_encode.present?
    self.elastify_options[:scroll_timeout] = model.opt_scroll_timeout if model.opt_scroll_timeout.present?
end