Class: TestConfig::ConfigFile
- Inherits:
-
Object
- Object
- TestConfig::ConfigFile
- Defined in:
- lib/test_config/config_file.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
- #evaluate ⇒ Object
-
#initialize(file) ⇒ ConfigFile
constructor
A new instance of ConfigFile.
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(file) ⇒ ConfigFile
Returns a new instance of ConfigFile.
5 6 7 8 |
# File 'lib/test_config/config_file.rb', line 5 def initialize(file) @file = file @data = HashMethods.deep_symbolize(self.to_h) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/test_config/config_file.rb', line 3 def data @data end |
#file ⇒ Object
Returns the value of attribute file.
3 4 5 |
# File 'lib/test_config/config_file.rb', line 3 def file @file end |
Instance Method Details
#evaluate ⇒ Object
18 19 20 |
# File 'lib/test_config/config_file.rb', line 18 def evaluate ERB.new(self.to_s).result end |
#to_h ⇒ Object
22 23 24 |
# File 'lib/test_config/config_file.rb', line 22 def to_h YAML.load(self.evaluate) || {} end |
#to_s ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/test_config/config_file.rb', line 10 def to_s begin File.read(@file) rescue SystemCallError raise "Could not locate configuration file: #{@file}." end end |