Class: Hako::YamlLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/hako/yaml_loader.rb

Defined Under Namespace

Classes: Visitor

Instance Method Summary collapse

Constructor Details

#initializeYamlLoader

Returns a new instance of YamlLoader.



7
8
9
# File 'lib/hako/yaml_loader.rb', line 7

def initialize
  @current_path = nil
end

Instance Method Details

#load(path) ⇒ Hash

Parameters:

  • path (String)

Returns:

  • (Hash)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/hako/yaml_loader.rb', line 13

def load(path)
  class_loader = Psych::ClassLoader.new
  scanner = Psych::ScalarScanner.new(class_loader)
  prev_path = @current_path
  @current_path = path
  visitor = Visitor.new(scanner, class_loader) do |_, val|
    load(@current_path.parent.join(val))
  end
  path.open do |f|
    visitor.accept(Psych.parse(f))
  end
ensure
  @current_path = prev_path
end