class Puppet::Functions::Function

Function

This class is the base class for all Puppet 4x Function API functions. A specialized class is created for each puppet function.

@api public

Public Class Methods

argument_mismatch(meth_name, &block) click to toggle source

Like `dispatch` but used for a specific type of argument mismatch. Will not be include in the list of valid parameter overloads for the function.

@param meth_name [Symbol] The name of the implementation method to call

when the signature defined in the block matches the arguments to a call
to the function.

@return [Void]

@api public

    # File lib/puppet/functions.rb
335 def self.argument_mismatch(meth_name, &block)
336   builder().instance_eval do
337     dispatch(meth_name, true, &block)
338   end
339 end
builder() click to toggle source

@api private

    # File lib/puppet/functions.rb
308 def self.builder
309   DispatcherBuilder.new(dispatcher, Puppet::Pops::Types::PCallableType::DEFAULT, loader)
310 end
dispatch(meth_name, &block) click to toggle source

Dispatch any calls that match the signature to the provided method name.

@param meth_name [Symbol] The name of the implementation method to call

when the signature defined in the block matches the arguments to a call
to the function.

@return [Void]

@api public

    # File lib/puppet/functions.rb
320 def self.dispatch(meth_name, &block)
321   builder().instance_eval do
322     dispatch(meth_name, false, &block)
323   end
324 end
local_types(&block) click to toggle source

Allows types local to the function to be defined to ease the use of complex types in a 4.x function. Within the given block, calls to `type` can be made with a string 'AliasType = ExistingType` can be made to define aliases. The defined aliases are available for further aliases, and in all dispatchers.

@since 4.5.0 @api public

    # File lib/puppet/functions.rb
349 def self.local_types(&block)
350   if loader.nil?
351     raise ArgumentError, _("No loader present. Call create_loaded_function(:myname, loader,...), instead of 'create_function' if running tests")
352   end
353   aliases = LocalTypeAliasesBuilder.new(loader, name)
354   aliases.instance_eval(&block)
355   # Add the loaded types to the builder
356   aliases.local_types.each do |type_alias_expr|
357     # Bind the type alias to the local_loader using the alias
358     t = Puppet::Pops::Loader::TypeDefinitionInstantiator.create_from_model(type_alias_expr, aliases.loader)
359 
360     # Also define a method for convenient access to the defined type alias.
361     # Since initial capital letter in Ruby means a Constant these names use a prefix of
362     # `type`. As an example, the type 'MyType' is accessed by calling `type_MyType`.
363     define_method("type_#{t.name}") { t }
364   end
365   # Store the loader in the class
366   @loader = aliases.loader
367 end
new(closure_scope, given_loader) click to toggle source

Creates a new function instance in the given closure scope (visibility to variables), and a loader (visibility to other definitions). The created function will either use the `given_loader` or (if it has local type aliases) a loader that was constructed from the loader used when loading the function's class.

TODO: It would be of value to get rid of the second parameter here, but that would break API.

Calls superclass method Puppet::Pops::Functions::Function::new
    # File lib/puppet/functions.rb
376 def self.new(closure_scope, given_loader)
377   super(closure_scope, @loader || given_loader)
378 end