Class: Lobster::Configuration
- Inherits:
-
Object
- Object
- Lobster::Configuration
- Defined in:
- lib/lobster/configuration.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(dir, env) ⇒ Configuration
constructor
A new instance of Configuration.
- #reload(dir, env) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(dir, env) ⇒ Configuration
Returns a new instance of Configuration.
5 6 7 |
# File 'lib/lobster/configuration.rb', line 5 def initialize(dir, env) reload(dir,env) end |
Instance Method Details
#[](key) ⇒ Object
38 39 40 |
# File 'lib/lobster/configuration.rb', line 38 def [](key) @config[key] end |
#reload(dir, env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/lobster/configuration.rb', line 9 def reload(dir, env) @config = { :monitor => true, :log_dir => 'log', :pid_dir => 'pids', :schedule_file => File.join('config', 'schedule.rb') } config_file_path = File.join(dir, 'config', 'lobster.yml') if File.exist? config_file_path config_file = YAML.load_file(config_file_path) @config.keys.each do |key| # environment-specific override val = config_file[env][key.to_s] if config_file[env] val = config_file[key.to_s] if val.nil? @config[key] = val unless val.nil? # keep default if no config end end # these keys cannot be set by the config file @config[:lobster_dir] = dir @config[:environment] = env # make paths absolute [:log_dir, :pid_dir, :schedule_file].each do |k| @config[k] = File.absolute_path(@config[k], dir) end end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/lobster/configuration.rb', line 42 def to_s @config.to_s end |