summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast/vardef.rb
blob: 6de1860c8780cc16f0d856e67e9b6ecf40630c9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'puppet/parser/ast/branch'

class Puppet::Parser::AST
  # Define a variable.  Stores the value in the current scope.
  class VarDef < AST::Branch

    associates_doc

    attr_accessor :name, :value, :append

    @settor = true

    # Look up our name and value, and store them appropriately.  The
    # lexer strips off the syntax stuff like '$'.
    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

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

end