Module: EsSearchable::Configurable

Included in:
EsSearchable
Defined in:
lib/es_searchable/configurable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/es_searchable/configurable.rb', line 5

def self.extended(base)
  base.const_set :SearchMethods,
    [:where, :like, :limit, :offset, :or, :not, :select, :and]
  
  base.const_set :DEFAULTS, { 
    log: true,
    retry_on_failure: 5, 
    async_callback: true,
    queue: 'elasticsearch',
    reload_on_failure: true, 
    hosts: ['localhost:9200'],
    logger: Logger.new($stdout)
  }
    
  base.class_eval do
    DEFAULTS.each do |k, v|
      self.define_singleton_method "#{k}=" do |value|
        self.options.merge!(k => value)
      end

      self.define_singleton_method k do
        self.options[k]
      end
    end
  end
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



32
33
34
# File 'lib/es_searchable/configurable.rb', line 32

def configure
  yield self
end

#optionsObject



36
37
38
# File 'lib/es_searchable/configurable.rb', line 36

def options
  @options ||= DEFAULTS.dup
end

#options=(opts) ⇒ Object



40
41
42
# File 'lib/es_searchable/configurable.rb', line 40

def options=(opts)
  @options = opts
end