Class: Config::Sources::YAMLSource

Inherits:
Object
  • Object
show all
Defined in:
lib/config/sources/yaml_source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ YAMLSource

Returns a new instance of YAMLSource.



9
10
11
# File 'lib/config/sources/yaml_source.rb', line 9

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/config/sources/yaml_source.rb', line 7

def path
  @path
end

Instance Method Details

#loadObject

returns a config hash from the YML file



14
15
16
17
18
19
20
21
22
23
# File 'lib/config/sources/yaml_source.rb', line 14

def load
  if @path and File.exist?(@path.to_s)
    result = YAML.load(ERB.new(IO.read(@path.to_s)).result)
  end
  result || {}
rescue Psych::SyntaxError => e
  raise "YAML syntax error occurred while parsing #{@path}. " \
        "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
        "Error: #{e.message}"
end