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.
- #to_s ⇒ Object
Constructor Details
#initialize(dir, env) ⇒ Configuration
Returns a new instance of Configuration.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/lobster/configuration.rb', line 5 def initialize(dir, env) @config = { :monitor => true, :log_dir => 'log', :pid_dir => File.join('/', 'var', 'run', 'lobster'), :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| val = config_file[env][key.to_s] # environment-specific override 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 |
Instance Method Details
#[](key) ⇒ Object
33 34 35 |
# File 'lib/lobster/configuration.rb', line 33 def [](key) @config[key] end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/lobster/configuration.rb', line 37 def to_s @config.to_s end |