Class: Isomer::Sources::Yaml
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
Attributes inherited from Base
#configuration, #errors, #parameters
Instance Method Summary collapse
-
#initialize(parameters, options = {}) ⇒ Yaml
constructor
A new instance of Yaml.
- #load ⇒ Object
Methods inherited from Base
#for, #load_and_validate, #validate
Constructor Details
#initialize(parameters, options = {}) ⇒ Yaml
Returns a new instance of Yaml.
6 7 8 9 10 11 12 13 14 |
# File 'lib/isomer/sources/yaml.rb', line 6 def initialize(parameters, ={}) @file = [:file].to_s raise Isomer::Error, "YAML source requires the 'file' parameter" if file.empty? @base = [:base] @required = !![:required] super(parameters) end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
4 5 6 |
# File 'lib/isomer/sources/yaml.rb', line 4 def base @base end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
4 5 6 |
# File 'lib/isomer/sources/yaml.rb', line 4 def file @file end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
4 5 6 |
# File 'lib/isomer/sources/yaml.rb', line 4 def required @required end |
Instance Method Details
#load ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/isomer/sources/yaml.rb', line 16 def load if File.exists?(file) values = YAML.load_file(file) if !values.is_a?(Hash) @configuration = {} elsif base && values.has_key?(base) @configuration = values[base] || {} else @configuration = values end else raise Isomer::Error, "Missing required configuration file '#{file}'" if required @configuration = {} end end |