Class: PostRunner::RuntimeConfig
- Inherits:
-
Object
- Object
- PostRunner::RuntimeConfig
- Defined in:
- lib/postrunner/RuntimeConfig.rb
Overview
Simple class to manage runtime configuration options which are persisted in a YAML file.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Shortcut for get_option.
-
#create_directory(dir, name) ⇒ Object
Ensure that the requested directory exists.
-
#get_option(name) ⇒ Object
Get a config option value.
-
#initialize(dir) ⇒ RuntimeConfig
constructor
Create a new RC object.
-
#set_option(name, value) ⇒ Object
Set a config option and update the RC file.
Constructor Details
#initialize(dir) ⇒ RuntimeConfig
Create a new RC object.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/postrunner/RuntimeConfig.rb', line 25 def initialize(dir) create_directory(dir, 'application data') @options = { :version => '0.0.0', :unit_system => :metric, :import_dir => nil, :data_dir => dir, :html_dir => File.join(dir, 'html') } @config_file = File.join(dir, 'config.yml') if File.exist?(@config_file) end |
Instance Method Details
#[](name) ⇒ Object
Shortcut for get_option.
42 43 44 |
# File 'lib/postrunner/RuntimeConfig.rb', line 42 def [](name) get_option(name) end |
#create_directory(dir, name) ⇒ Object
Ensure that the requested directory exists.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/postrunner/RuntimeConfig.rb', line 62 def create_directory(dir, name) return if Dir.exists?(dir) Log.info "Creating #{name} directory #{dir}" begin Dir.mkdir(dir) rescue StandardError Log.fatal "Cannot create #{name} directory #{dir}: #{$!}" end end |
#get_option(name) ⇒ Object
Get a config option value.
49 50 51 |
# File 'lib/postrunner/RuntimeConfig.rb', line 49 def get_option(name) @options[name] end |
#set_option(name, value) ⇒ Object
Set a config option and update the RC file.
56 57 58 59 |
# File 'lib/postrunner/RuntimeConfig.rb', line 56 def set_option(name, value) @options[name] = value end |