Class: Filegen::DataSources::Yaml

Inherits:
Object
  • Object
show all
Defined in:
lib/filegen/data_sources/yaml.rb

Overview

Data source which makes yaml files available

Instance Method Summary collapse

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