Class: NeuroHmmerApp::Config
- Inherits:
-
Object
- Object
- NeuroHmmerApp::Config
- Extended by:
- Forwardable
- Defined in:
- lib/neurohmmerapp/config.rb
Overview
Capture our configuration system.
Instance Attribute Summary collapse
-
#config_file ⇒ Object
readonly
Returns the value of attribute config_file.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Get.
-
#[]=(key, value) ⇒ Object
Set.
-
#include?(key) ⇒ Boolean
Exists?.
-
#initialize(data = {}) ⇒ Config
constructor
A new instance of Config.
-
#write_config_file ⇒ Object
Write config data to config file.
Constructor Details
#initialize(data = {}) ⇒ Config
Returns a new instance of Config.
11 12 13 14 15 16 17 |
# File 'lib/neurohmmerapp/config.rb', line 11 def initialize(data = {}) @data = symbolise data @config_file = @data.delete(:config_file) || default_config_file @config_file = File.(@config_file) @data = parse_config_file.update @data @data = defaults.update @data end |
Instance Attribute Details
#config_file ⇒ Object (readonly)
Returns the value of attribute config_file.
19 20 21 |
# File 'lib/neurohmmerapp/config.rb', line 19 def config_file @config_file end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
19 20 21 |
# File 'lib/neurohmmerapp/config.rb', line 19 def data @data end |
Instance Method Details
#[](key) ⇒ Object
Get.
22 23 24 |
# File 'lib/neurohmmerapp/config.rb', line 22 def [](key) data[key] end |
#[]=(key, value) ⇒ Object
Set.
27 28 29 |
# File 'lib/neurohmmerapp/config.rb', line 27 def []=(key, value) data[key] = value end |
#include?(key) ⇒ Boolean
Exists?
32 33 34 |
# File 'lib/neurohmmerapp/config.rb', line 32 def include?(key) data.include? key end |
#write_config_file ⇒ Object
Write config data to config file.
37 38 39 40 41 42 43 |
# File 'lib/neurohmmerapp/config.rb', line 37 def write_config_file return unless config_file File.open(config_file, 'w') do |f| f.puts(data.delete_if { |_, v| v.nil? }.to_yaml) end end |