Class: Waistband::Configuration
- Inherits:
-
Object
- Object
- Waistband::Configuration
- Includes:
- Singleton
- Defined in:
- lib/waistband/configuration.rb
Instance Attribute Summary collapse
-
#config_dir ⇒ Object
Returns the value of attribute config_dir.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#timeout ⇒ Object
writeonly
Sets the attribute timeout.
Instance Method Summary collapse
- #client ⇒ Object
- #index(name) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #method_missing(method_name, *args, &block) ⇒ Object
- #reset_timeout ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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
38 39 40 41 |
# File 'lib/waistband/configuration.rb', line 38 def method_missing(method_name, *args, &block) return @yml_config[method_name] if @yml_config.has_key?(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 (readonly)
Returns the value of attribute env.
13 14 15 |
# File 'lib/waistband/configuration.rb', line 13 def env @env end |
#logger ⇒ Object
Returns the value of attribute logger.
11 12 13 |
# File 'lib/waistband/configuration.rb', line 11 def logger @logger 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
43 44 45 |
# File 'lib/waistband/configuration.rb', line 43 def client ::Waistband::Client.from_config(client_config_hash) end |
#index(name) ⇒ Object
32 33 34 35 36 |
# File 'lib/waistband/configuration.rb', line 32 def index(name) return @indexes[name] if @indexes[name] yml = load_yml_with_erb(File.join(config_dir, "waistband_#{name}.yml")) @indexes[name] = yml[@env].with_indifferent_access end |
#reset_timeout ⇒ Object
47 48 49 |
# File 'lib/waistband/configuration.rb', line 47 def reset_timeout remove_instance_variable '@timeout' end |
#setup ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# 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' yml = load_yml_with_erb(File.join(config_dir, 'waistband.yml')) @yml_config = yml[@env].with_indifferent_access @adapter = @yml_config.delete('adapter') end |