Class: Bolt::PAL::YamlPlan::Loader::PuppetVisitor

Inherits:
Psych::Visitors::NoAliasRuby
  • Object
show all
Defined in:
lib/bolt/pal/yaml_plan/loader.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_visitorObject



12
13
14
15
16
# File 'lib/bolt/pal/yaml_plan/loader.rb', line 12

def self.create_visitor
  class_loader = Psych::ClassLoader::Restricted.new([], [])
  scanner = Psych::ScalarScanner.new(class_loader)
  new(scanner, class_loader)
end

Instance Method Details

#deserialize(node) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bolt/pal/yaml_plan/loader.rb', line 18

def deserialize(node)
  if node.quoted
    case node.style
    when Psych::Nodes::Scalar::SINGLE_QUOTED
      # Single-quoted strings are treated literally
      # @ss is a ScalarScanner, from the base ToRuby visitor class
      node.value
    when Psych::Nodes::Scalar::DOUBLE_QUOTED
      DoubleQuotedString.new(node.value)
    # | style string or > style string
    when Psych::Nodes::Scalar::LITERAL, Psych::Nodes::Scalar::FOLDED
      CodeLiteral.new(node.value)
    # This one shouldn't be possible
    else
      @ss.tokenize(node.value)
    end
  else
    value = @ss.tokenize(node.value)
    if value.is_a?(String)
      BareString.new(value)
    else
      value
    end
  end
end