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

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

Overview

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

Constant Summary

Constants inherited from Puppet::Parser::AST

AST

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Instance Attribute Summary collapse

Attributes inherited from Branch

#children, #pin

Attributes inherited from Puppet::Parser::AST

#file, #line, #parent, #scope

Attributes included from Util::Docs

#doc, #nodoc

Instance Method Summary collapse

Methods inherited from Branch

#initialize

Methods inherited from Puppet::Parser::AST

associates_doc, #evaluate_match, #initialize, #inspect, #parsefail, #parsewrap, #safeevaluate, settor?, #use_docs

Methods included from Util::Docs

#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub

Methods included from Util::MethodHelper

#requiredopts, #set_options, #symbolize_options

Methods included from Util::Errors

#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail

Constructor Details

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

Instance Attribute Details

#appendObject

Returns the value of attribute append.



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

def append
  @append
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#eachObject



28
29
30
# File 'lib/vendor/puppet/parser/ast/vardef.rb', line 28

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 ‘$’.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vendor/puppet/parser/ast/vardef.rb', line 15

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
end