Class: Hako::YamlLoader::Visitor

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

Constant Summary collapse

INCLUDE_TAG =
'tag:include'
SHOVEL =
'<<'

Instance Method Summary collapse

Constructor Details

#initialize(scanner, class_loader, &block) ⇒ Visitor

Returns a new instance of Visitor.



32
33
34
35
# File 'lib/hako/yaml_loader.rb', line 32

def initialize(scanner, class_loader, &block)
  super(scanner, class_loader)
  @domain_types[INCLUDE_TAG] = [INCLUDE_TAG, block]
end

Instance Method Details

#revive_hash(hash, o) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/hako/yaml_loader.rb', line 37

def revive_hash(hash, o)
  super(hash, o).tap do |r|
    if r[SHOVEL].is_a?(Hash)
      h2 = {}
      r.each do |k, v|
        if k == SHOVEL
          h2.merge!(v)
        else
          h2[k] = v
        end
      end
      r.replace(h2)
    end
  end
end