Class: GrapeOnRails::Sources::YAMLSource
- Inherits:
-
Object
- Object
- GrapeOnRails::Sources::YAMLSource
- Defined in:
- lib/grape_on_rails/sources/yaml_source.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path) ⇒ YAMLSource
constructor
A new instance of YAMLSource.
- #load ⇒ Object
Constructor Details
#initialize(path) ⇒ YAMLSource
Returns a new instance of YAMLSource.
9 10 11 |
# File 'lib/grape_on_rails/sources/yaml_source.rb', line 9 def initialize path @path = path end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/grape_on_rails/sources/yaml_source.rb', line 7 def path @path end |
Instance Method Details
#load ⇒ Object
13 14 15 16 17 18 |
# File 'lib/grape_on_rails/sources/yaml_source.rb', line 13 def load @path && File.exist?(@path.to_s) ? YAML.safe_load(ERB.new(IO.read(@path.to_s)).result) : {} rescue Psych::SyntaxError => e raise "YAML syntax error occurred while parsing #{@path}. " \ "Error: #{e.message}" end |