Class: TestConfig::ConfigFile

Inherits:
Object
  • Object
show all
Defined in:
lib/test_config/config_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/test_config/config_file.rb', line 3

def data
  @data
end

#fileObject

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

#evaluateObject



18
19
20
# File 'lib/test_config/config_file.rb', line 18

def evaluate
  ERB.new(self.to_s).result
end

#to_hObject



22
23
24
# File 'lib/test_config/config_file.rb', line 22

def to_h
  YAML.load(self.evaluate) || {}
end

#to_sObject



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