Class: EasySettings::YamlSource

Inherits:
Object
  • Object
show all
Defined in:
lib/easy-settings/yaml_source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ YamlSource

Returns a new instance of YamlSource.



7
8
9
# File 'lib/easy-settings/yaml_source.rb', line 7

def initialize(path)
  @path = path.to_s
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/easy-settings/yaml_source.rb', line 5

def path
  @path
end

Instance Method Details

#loadObject



11
12
13
14
15
# File 'lib/easy-settings/yaml_source.rb', line 11

def load
  File.exist?(path) ? (YAML.load(ERB.new(IO.read(path)).result) || {}) : {}
rescue StandardError => e
  raise "Error occurred while parsing #{path}: #{e.message}"
end