Class: Waistband::Configuration
- Inherits:
-
Object
- Object
- Waistband::Configuration
show all
- Includes:
- Singleton
- Defined in:
- lib/waistband/configuration.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Configuration.
15
16
17
18
|
# File 'lib/waistband/configuration.rb', line 15
def initialize
@yml_config = {}
@indexes = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
46
47
48
49
|
# File 'lib/waistband/configuration.rb', line 46
def method_missing(method_name, *args, &block)
return @yml_config[method_name] if @yml_config[method_name]
super
end
|
Instance Attribute Details
#config_dir ⇒ Object
Returns the value of attribute config_dir.
11
12
13
|
# File 'lib/waistband/configuration.rb', line 11
def config_dir
@config_dir
end
|
#env ⇒ Object
Returns the value of attribute env.
13
14
15
|
# File 'lib/waistband/configuration.rb', line 13
def env
@env
end
|
#timeout=(value) ⇒ Object
Sets the attribute timeout
12
13
14
|
# File 'lib/waistband/configuration.rb', line 12
def timeout=(value)
@timeout = value
end
|
Instance Method Details
#client ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/waistband/configuration.rb', line 57
def client
client_hash = {
adapter: @adapter,
hosts: hosts,
randomize_hosts: true,
retry_on_failure: retries,
reload_on_failure: reload_on_failure,
transport_options: {
request: {
open_timeout: timeout,
timeout: timeout
}
}
}
Elasticsearch::Client.new client_hash
end
|
#hosts ⇒ Object
51
52
53
54
55
|
# File 'lib/waistband/configuration.rb', line 51
def hosts
@hosts ||= @yml_config['servers'].map do |server_name, config|
config
end
end
|
#index(name) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/waistband/configuration.rb', line 36
def index(name)
return @indexes[name] if @indexes[name]
if defined?(ERB)
yml = YAML.load(ERB.new(File.read("#{config_dir}/waistband_#{name}.yml")).result)
else
yml = YAML.load_file("#{config_dir}/waistband_#{name}.yml")
end
@indexes[name] = yml[@env].with_indifferent_access
end
|
#reset_timeout ⇒ Object
75
76
77
|
# File 'lib/waistband/configuration.rb', line 75
def reset_timeout
remove_instance_variable '@timeout'
end
|
#setup ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/waistband/configuration.rb', line 20
def setup
self.config_dir = default_config_dir unless config_dir
raise "Please define a valid `config_dir` configuration variable!" unless config_dir
raise "Couldn't find configuration directory #{config_dir}" unless File.exist?(config_dir)
@env ||= ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
if defined?(ERB)
yml = YAML.load(ERB.new(File.read("#{config_dir}/waistband.yml")).result)
else
yml = YAML.load_file("#{config_dir}/waistband.yml")
end
@yml_config = yml[@env].with_indifferent_access
@adapter = @yml_config.delete('adapter')
end
|