class Config::Sources::YAMLSource
Attributes
namespace[RW]
path[RW]
Public Class Methods
new(path, namespace=nil)
click to toggle source
# File lib/config/sources/yaml_source.rb, line 9 def initialize(path, namespace=nil) @path = path @namespace = namespace end
Public Instance Methods
load()
click to toggle source
returns a config hash from the YML file
# File lib/config/sources/yaml_source.rb, line 15 def load if @path and File.exist?(@path.to_s) result = YAML.load(ERB.new(IO.read(@path.to_s)).result) end if self.namespace namespaces = self.namespace.split("/") result = namespaces.reverse.inject(result || {}) { |acc, space| { space => acc } } 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