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

Constructor Details

#initialize(scanner, class_loader, file) ⇒ PuppetVisitor

Returns a new instance of PuppetVisitor.


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

def initialize(scanner, class_loader, file)
  super(scanner, class_loader)
  @file = file
end

Class Method Details

.create_visitor(source_ref) ⇒ Object


17
18
19
20
21
# File 'lib/bolt/pal/yaml_plan/loader.rb', line 17

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

Instance Method Details

#deserialize(node) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bolt/pal/yaml_plan/loader.rb', line 23

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, @file, node.start_line + 1)
    # | style string
    when Psych::Nodes::Scalar::LITERAL
      CodeLiteral.new(node.value, @file, node.start_line + 1)
    # > style string
    else
      @ss.tokenize(node.value)
    end
  else
    value = @ss.tokenize(node.value)
    if value.is_a?(String)
      BareString.new(value, @file, node.start_line + 1)
    else
      value
    end
  end
end