Class: Ettin::Sources::YamlSource
- Inherits:
-
Ettin::Source
- Object
- Ettin::Source
- Ettin::Sources::YamlSource
- Defined in:
- lib/ettin/sources/yaml_source.rb
Overview
Config data from a yaml file
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path) ⇒ YamlSource
constructor
A new instance of YamlSource.
- #load ⇒ Object
Methods inherited from Ettin::Source
for, register, register_default, registry
Constructor Details
#initialize(path) ⇒ YamlSource
Returns a new instance of YamlSource.
18 19 20 |
# File 'lib/ettin/sources/yaml_source.rb', line 18 def initialize(path) @path = path end |
Class Method Details
.handles?(_target) ⇒ Boolean
14 15 16 |
# File 'lib/ettin/sources/yaml_source.rb', line 14 def self.handles?(_target) true end |
Instance Method Details
#load ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ettin/sources/yaml_source.rb', line 22 def load return {} unless File.exist?(path) begin YAML.safe_load(ERB.new(File.read(path)).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.}" end end |