Class: GrapeOnRails::Sources::YAMLSource

Inherits:
Object
  • Object
show all
Defined in:
lib/grape_on_rails/sources/yaml_source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject

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

#loadObject



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