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.



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

def initialize
  @current_path = nil
end

Instance Method Details

#load(path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/hako/yaml_loader.rb', line 10

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