Sha256: 668814438a0cd99512e2a894ee1480868344f1baf2494313dfee006bb9b0f6e3

Contents?: true

Size: 1.35 KB

Versions: 17

Compression:

Stored size: 1.35 KB

Contents

require 'puppet/parser/ast/branch'

class Puppet::Parser::AST
  # An AST object to call a function.
  class Function < AST::Branch

    associates_doc

    attr_accessor :name, :arguments

    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

    def initialize(hash)
      @ftype = hash[:ftype] || :rvalue
      hash.delete(:ftype) if hash.include? :ftype

      super(hash)

      # Lastly, check the parity
    end

    def to_s
      args = arguments.is_a?(ASTArray) ? arguments.to_s.gsub(/\[(.*)\]/,'\1') : arguments
      "#{name}(#{args})"
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/puppet-3.1.0/lib/puppet/parser/ast/function.rb
puppet-3.1.1 lib/puppet/parser/ast/function.rb
librarian-puppet-0.9.8 vendor/gems/ruby/1.9.1/gems/puppet-3.1.0/lib/puppet/parser/ast/function.rb
puppet-3.1.0 lib/puppet/parser/ast/function.rb
puppet-3.1.0.rc2 lib/puppet/parser/ast/function.rb
puppet-3.1.0.rc1 lib/puppet/parser/ast/function.rb
puppet-3.0.2 lib/puppet/parser/ast/function.rb
puppet-3.0.2.rc3 lib/puppet/parser/ast/function.rb
puppet-3.0.2.rc2 lib/puppet/parser/ast/function.rb
puppet-3.0.2.rc1 lib/puppet/parser/ast/function.rb
puppet-3.0.1 lib/puppet/parser/ast/function.rb
puppet-3.0.1.rc1 lib/puppet/parser/ast/function.rb
puppet-3.0.0 lib/puppet/parser/ast/function.rb
puppet-3.0.0.rc8 lib/puppet/parser/ast/function.rb
puppet-3.0.0.rc7 lib/puppet/parser/ast/function.rb
puppet-3.0.0.rc5 lib/puppet/parser/ast/function.rb
puppet-3.0.0.rc4 lib/puppet/parser/ast/function.rb