Class: Chewy::Config

Inherits:
Object
  • 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.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/chewy/config.rb', line 51

def initialize
  @settings = {}
  @root_strategy = :base
  @request_strategy = :atomic
  @console_strategy = :urgent
  @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 = 'text'.freeze
  @search_class = build_search_class(Chewy::Search::Request)
end

Instance Attribute Details

#console_strategyObject

Returns the value of attribute console_strategy.



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

def console_strategy
  @console_strategy
end

#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

#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

#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 (readonly)

Returns the value of attribute search_class.



43
44
45
# File 'lib/chewy/config.rb', line 43

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.



43
44
45
# File 'lib/chewy/config.rb', line 43

def transport_logger
  @transport_logger
end

#transport_tracerObject

Returns the value of attribute transport_tracer.



43
44
45
# File 'lib/chewy/config.rb', line 43

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



47
48
49
# File 'lib/chewy/config.rb', line 47

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 heavy 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



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

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