Module: OMF::Base::YAML
- Defined in:
- lib/omf_base/load_yaml.rb
Defined Under Namespace
Classes: YamlFileNotFound
Class Method Summary collapse
-
.load(file_name, opts = {}) ⇒ Object
A method to load YAML files.
Class Method Details
.load(file_name, opts = {}) ⇒ Object
A method to load YAML files
file_name - Name of file to load opts -
> :default - value to use if file can’t be loaded
> :path - array of directories to look for file
raise YamlFileNotFound if YAML file can’t be found
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/omf_base/load_yaml.rb', line 24 def self.load(file_name, opts = {}) if (file_name.split('.').length == 1) file_name = file_name + '.yaml' end path = opts[:path] || ['.', File.dirname(__FILE__)] begin path.each do |d| begin return _load_file(d + '/' + file_name) rescue YamlFileNotFound => ex end end if (default = opts[:default]) return _symbolize(default) end raise YamlFileNotFound.new("Can't read YAML file '#{file_name}' in '#{path.join(':')}'") end end |