class Puppet::Parser::AST::Function

An AST object to call a function.

Attributes

arguments[RW]
name[RW]

Public Class Methods

new(hash) click to toggle source
Calls superclass method
# File lib/puppet/parser/ast/function.rb, line 34
def initialize(hash)
  @ftype = hash[:ftype] || :rvalue
  hash.delete(:ftype) if hash.include? :ftype

  super(hash)

  # Lastly, check the parity
end

Public Instance Methods

evaluate(scope) click to toggle source
# File lib/puppet/parser/ast/function.rb, line 11
def evaluate(scope)
  # Make sure it's a defined function
  raise Puppet::ParseError, "Unknown function #{@name}" unless Puppet::Parser::Functions.function(@name)

  # Now check that it's been used correctly
  case @ftype
  when :rvalue
    raise Puppet::ParseError, "Function '#{@name}' does not return a value" unless Puppet::Parser::Functions.rvalue?(@name)
  when :statement
    if Puppet::Parser::Functions.rvalue?(@name)
      raise Puppet::ParseError,
        "Function '#{@name}' must be the value of a statement"
    end
  else
    raise Puppet::DevError, "Invalid function type #{@ftype.inspect}"
  end

  # We don't need to evaluate the name, because it's plaintext
  args = @arguments.safeevaluate(scope).map { |x| x == :undef ? '' : x }

  scope.send("function_#{@name}", args)
end
to_s() click to toggle source
# File lib/puppet/parser/ast/function.rb, line 43
def to_s
  args = arguments.is_a?(ASTArray) ? arguments.to_s.gsub(/\[(.*)\]/,'\1') : arguments
  "#{name}(#{args})"
end