Class: Puppet::Parser::AST::VarDef

Inherits:
Branch show all
Defined in:
lib/puppet/parser/ast/vardef.rb

Overview

Define a variable. Stores the value in the current scope.

Instance Attribute Summary collapse

Attributes inherited from Branch

#children, #pin

Instance Method Summary collapse

Methods inherited from Branch

#initialize

Constructor Details

This class inherits a constructor from Puppet::Parser::AST::Branch

Instance Attribute Details

#appendObject



9
10
11
# File 'lib/puppet/parser/ast/vardef.rb', line 9

def append
  @append
end

#nameObject



9
10
11
# File 'lib/puppet/parser/ast/vardef.rb', line 9

def name
  @name
end

#valueObject



9
10
11
# File 'lib/puppet/parser/ast/vardef.rb', line 9

def value
  @value
end

Instance Method Details

#eachObject



33
34
35
# File 'lib/puppet/parser/ast/vardef.rb', line 33

def each
  [@name,@value].each { |child| yield child }
end

#evaluate(scope) ⇒ Object

Look up our name and value, and store them appropriately. The lexer strips off the syntax stuff like ‘$’.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/puppet/parser/ast/vardef.rb', line 13

def evaluate(scope)
  value = @value.safeevaluate(scope)
  if name.is_a?(HashOrArrayAccess)
    name.assign(scope, value)
  else
    name = @name.safeevaluate(scope)

    parsewrap do
      scope.setvar(name,value, :file => file, :line => line, :append => @append)
    end
  end
  if @append
    # Produce resulting value from append operation
    scope[name]
  else
    # Produce assigned value
    value
  end
end