Class: SafeYAML::SafeToRubyVisitor

Inherits:
Psych::Visitors::ToRuby
  • Object
show all
Defined in:
lib/safe_yaml/safe_to_ruby_visitor.rb

Constant Summary collapse

INITIALIZE_ARITY =
superclass.instance_method(:initialize).arity

Instance Method Summary collapse

Constructor Details

#initialize(resolver) ⇒ SafeToRubyVisitor

Returns a new instance of SafeToRubyVisitor.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/safe_yaml/safe_to_ruby_visitor.rb', line 5

def initialize(resolver)
  case INITIALIZE_ARITY
  when 2
    # https://github.com/tenderlove/psych/blob/v2.0.0/lib/psych/visitors/to_ruby.rb#L14-L28
    loader  = Psych::ClassLoader.new
    scanner = Psych::ScalarScanner.new(loader)
    super(scanner, loader)

  else
    super()
  end

  @resolver = resolver
end

Instance Method Details

#accept(node) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/safe_yaml/safe_to_ruby_visitor.rb', line 20

def accept(node)
  if node.tag
    SafeYAML.tag_safety_check!(node.tag, @resolver.options)
    return super
  end

  @resolver.resolve_node(node)
end