Class: Chewy::Config

Inherits:
Object show all
Includes:
Singleton
Defined in:
lib/chewy/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



49
50
51
52
53
54
55
56
57
# File 'lib/chewy/config.rb', line 49

def initialize
  @settings = {}
  @query_mode = :must
  @filter_mode = :and
  @root_strategy = :base
  @request_strategy = :atomic
  @use_after_commit_callbacks = true
  @indices_path = 'app/chewy'
end

Instance Attribute Details

#filter_modeObject

Returns the value of attribute filter_mode.



5
6
7
# File 'lib/chewy/config.rb', line 5

def filter_mode
  @filter_mode
end

#indices_pathObject

Returns the value of attribute indices_path.



5
6
7
# File 'lib/chewy/config.rb', line 5

def indices_path
  @indices_path
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/chewy/config.rb', line 5

def logger
  @logger
end

#post_filter_modeObject

Returns the value of attribute post_filter_mode.



5
6
7
# File 'lib/chewy/config.rb', line 5

def post_filter_mode
  @post_filter_mode
end

#query_modeObject

Returns the value of attribute query_mode.



5
6
7
# File 'lib/chewy/config.rb', line 5

def query_mode
  @query_mode
end

#request_strategyObject

Returns the value of attribute request_strategy.



5
6
7
# File 'lib/chewy/config.rb', line 5

def request_strategy
  @request_strategy
end

#root_strategyObject

Returns the value of attribute root_strategy.



5
6
7
# File 'lib/chewy/config.rb', line 5

def root_strategy
  @root_strategy
end

#settingsObject

Returns the value of attribute settings.



5
6
7
# File 'lib/chewy/config.rb', line 5

def settings
  @settings
end

#transport_loggerObject

Returns the value of attribute transport_logger.



5
6
7
# File 'lib/chewy/config.rb', line 5

def transport_logger
  @transport_logger
end

#transport_tracerObject

Returns the value of attribute transport_tracer.



5
6
7
# File 'lib/chewy/config.rb', line 5

def transport_tracer
  @transport_tracer
end

#use_after_commit_callbacksObject

Returns the value of attribute use_after_commit_callbacks.



5
6
7
# File 'lib/chewy/config.rb', line 5

def use_after_commit_callbacks
  @use_after_commit_callbacks
end

Class Method Details

.delegatedObject



45
46
47
# File 'lib/chewy/config.rb', line 45

def self.delegated
  public_instance_methods - superclass.public_instance_methods - Singleton.public_instance_methods
end

Instance Method Details

#configurationObject

Chewy core configurations. There is two ways to set it up: use ‘Chewy.settings=` method or, for Rails application, create `config/chewy.yml` file. Btw, `config/chewy.yml` supports ERB the same way as ActiveRecord’s config.

Configuration options:

1. Chewy client options. All the options Elasticsearch::Client
   supports.

     test:
       host: 'localhost:9250'

2. Chewy self-configuration:

   :prefix - used as prefix for any index created.

     test:
       host: 'localhost:9250'
       prefix: test<%= ENV['TEST_ENV_NUMBER'] %>

   Then UsersIndex.index_name will be "test42_users"
   in case TEST_ENV_NUMBER=42

   :wait_for_status - if this option set - chewy actions such
   as creating or deleting index, importing data will wait for
   the status specified. Extremely useful for tests under havy
   indexes manipulations.

     test:
       host: 'localhost:9250'
       wait_for_status: green

3. Index settings. All the possible ElasticSearch index settings.
   Will be merged as defaults with index settings on every index
   creation.

     test: &test
       host: 'localhost:9250'
       index:
         number_of_shards: 1
         number_of_replicas: 0


112
113
114
115
116
117
118
# File 'lib/chewy/config.rb', line 112

def configuration
  yaml_settings.merge(settings.deep_symbolize_keys).tap do |configuration|
    configuration[:logger] = transport_logger if transport_logger
    configuration[:indices_path] ||= indices_path if indices_path
    configuration.merge!(tracer: transport_tracer) if transport_tracer
  end
end

#configuration=(options) ⇒ Object



120
121
122
123
# File 'lib/chewy/config.rb', line 120

def configuration=(options)
  ActiveSupport::Deprecation.warn("`Chewy.configuration = {foo: 'bar'}` method is deprecated and will be removed soon, use `Chewy.settings = {foo: 'bar'}` method instead")
  self.settings = options
end