Method: Puppet::Functions.create_function

Defined in:
lib/puppet/functions.rb

.create_function(func_name, function_base = Function, &block) ⇒ Class<Function>

Returns the newly created Function class.

Parameters:

  • func_name (String, Symbol)

    a simple or qualified function name

  • block (Proc)

    the block that defines the methods and dispatch of the Function to create

Returns:

  • (Class<Function>)

    the newly created Function class



186
187
188
189
190
191
192
193
194
195
196
# File 'lib/puppet/functions.rb', line 186

def self.create_function(func_name, function_base = Function, &block)
  # Ruby < 2.1.0 does not have method on Binding, can only do eval
  # and it will fail unless protected with an if defined? if the local
  # variable does not exist in the block's binder.
  #

  loader = block.binding.eval('loader_injected_arg if defined?(loader_injected_arg)')
  create_loaded_function(func_name, loader, function_base, &block)
rescue StandardError => e
  raise ArgumentError, _("Function Load Error for function '%{function_name}': %{message}") % { function_name: func_name, message: e.message }
end