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.


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/chewy/config.rb', line 71

def initialize
  @settings = {}
  @query_mode = :must
  @filter_mode = :and
  @root_strategy = :base
  @request_strategy = :atomic
  @use_after_commit_callbacks = true
  @reset_disable_refresh_interval = false
  @reset_no_replicas = false
  @disable_refresh_async = false
  @indices_path = 'app/chewy'
  @default_root_options = {}
  @default_field_type = 'string'.freeze
  self.search_class = Chewy::Search::Request
end

Instance Attribute Details

#default_field_typeObject

Returns the value of attribute default_field_type


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

def default_field_type
  @default_field_type
end

#default_root_optionsObject

Returns the value of attribute default_root_options


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

def default_root_options
  @default_root_options
end

#disable_refresh_asyncObject

Returns the value of attribute disable_refresh_async


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

def disable_refresh_async
  @disable_refresh_async
end

#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

#reset_disable_refresh_intervalObject

Returns the value of attribute reset_disable_refresh_interval


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

def reset_disable_refresh_interval
  @reset_disable_refresh_interval
end

#reset_no_replicasObject

Returns the value of attribute reset_no_replicas


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

def reset_no_replicas
  @reset_no_replicas
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

#search_classObject

Returns the value of attribute search_class


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

def search_class
  @search_class
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


67
68
69
# File 'lib/chewy/config.rb', line 67

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


144
145
146
147
148
149
150
# File 'lib/chewy/config.rb', line 144

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