class Chewy::Config
Attributes
before_es_request_filter[RW]
console_strategy[RW]
default_field_type[RW]
default_root_options[RW]
disable_refresh_async[RW]
import_scope_cleanup_behavior[RW]
indices_path[RW]
logger[RW]
request_strategy[RW]
reset_disable_refresh_interval[RW]
reset_no_replicas[RW]
root_strategy[RW]
search_class[R]
settings[RW]
transport_logger[R]
transport_tracer[R]
use_after_commit_callbacks[RW]
Public Class Methods
delegated()
click to toggle source
# File lib/chewy/config.rb, line 52 def self.delegated public_instance_methods - superclass.public_instance_methods - Singleton.public_instance_methods end
new()
click to toggle source
# File lib/chewy/config.rb, line 56 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 @import_scope_cleanup_behavior = :warn @search_class = build_search_class(Chewy::Search::Request) end
Public Instance Methods
configuration()
click to toggle source
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
# File lib/chewy/config.rb, line 125 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
transport_logger=(logger)
click to toggle source
# File lib/chewy/config.rb, line 72 def transport_logger=(logger) Chewy.client.transport.transport.logger = logger @transport_logger = logger end
transport_tracer=(tracer)
click to toggle source
# File lib/chewy/config.rb, line 77 def transport_tracer=(tracer) Chewy.client.transport.transport.tracer = tracer @transport_tracer = tracer end
Private Instance Methods
build_search_class(base)
click to toggle source
# File lib/chewy/config.rb, line 151 def build_search_class(base) Class.new(base).tap do |search_class| search_class.send :include, Chewy::Search::Pagination::Kaminari if defined?(::Kaminari) end end
build_yaml_settings()
click to toggle source
# File lib/chewy/config.rb, line 139 def build_yaml_settings return unless defined?(Rails::VERSION) file = Rails.root.join('config', 'chewy.yml') return unless File.exist?(file) yaml = ERB.new(File.read(file)).result hash = YAML.unsafe_load(yaml) hash[Rails.env].try(:deep_symbolize_keys) if hash end
yaml_settings()
click to toggle source
# File lib/chewy/config.rb, line 135 def yaml_settings @yaml_settings ||= build_yaml_settings || {} end