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.
Instance Method Summary collapse
- #index(name) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #method_missing(method_name, *args, &block) ⇒ Object
- #servers ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
14 15 16 17 |
# File 'lib/waistband/configuration.rb', line 14 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
31 32 33 34 35 |
# File 'lib/waistband/configuration.rb', line 31 def method_missing(method_name, *args, &block) return current_server[method_name] if current_server[method_name] 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 (readonly)
Returns the value of attribute env.
12 13 14 |
# File 'lib/waistband/configuration.rb', line 12 def env @env end |
Instance Method Details
#index(name) ⇒ Object
27 28 29 |
# File 'lib/waistband/configuration.rb', line 27 def index(name) @indexes[name] ||= YAML.load_file("#{config_dir}/waistband_#{name}.yml")[@env].with_indifferent_access end |
#servers ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/waistband/configuration.rb', line 37 def servers @servers ||= @yml_config['servers'].map do |server_name, config| config.merge({ '_id' => Digest::SHA1.hexdigest("#{config['host']}:#{config['port']}") }) end end |
#setup ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/waistband/configuration.rb', line 19 def setup 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_config = YAML.load_file("#{config_dir}/waistband.yml")[@env].with_indifferent_access end |