Class: Filegen::DataSources::Yaml
- Inherits:
-
Object
- Object
- Filegen::DataSources::Yaml
- Defined in:
- lib/filegen/data_sources/yaml.rb
Overview
Data source which makes yaml files available
Instance Method Summary collapse
- #fetch(key, default_value = nil) ⇒ Object
-
#initialize(file) ⇒ Yaml
constructor
Create data source.
Constructor Details
#initialize(file) ⇒ Yaml
Create data source
14 15 16 17 18 |
# File 'lib/filegen/data_sources/yaml.rb', line 14 def initialize(file) @source = HashWithIndifferentAccess.new(Psych.load_file(file)) rescue Errno::ENOENT raise Exceptions::YamlFileNotFound, JSON.dump(file: file) end |
Instance Method Details
#fetch(key, default_value = nil) ⇒ Object
20 21 22 |
# File 'lib/filegen/data_sources/yaml.rb', line 20 def fetch(key, default_value = nil) source[key.to_sym] || source[key.to_s] || default_value end |