Evaluate the dispatches defined as {Puppet::Pops::Functions::Dispatch} instances to call the appropriate method on the {Puppet::Pops::Functions::Function} instance.
@api private
Adds a regular dispatch for one method name
@param type [Puppet::Pops::Types::PArrayType, Puppet::Pops::Types::PTupleType] - type describing signature @param method_name [String] - the name of the method that will be called when type matches given arguments @param names [Array<String>] - array with names matching the number of parameters specified by type (or empty array)
@api private
# File lib/puppet/pops/functions/dispatcher.rb, line 48 def add_dispatch(type, method_name, param_names, block_name, injections, weaving, last_captures) @dispatchers << Puppet::Pops::Functions::Dispatch.new(type, method_name, param_names, block_name, injections, weaving, last_captures) end
Dispatches the call to the first found signature (entry with matching type).
@param instance [Puppet::Functions::Function] - the function to call @param calling_scope [T.B.D::Scope] - the scope of the caller @param args [Array<Object>] - the given arguments in the form of an Array @return [Object] - what the called function produced
@api private
# File lib/puppet/pops/functions/dispatcher.rb, line 30 def dispatch(instance, calling_scope, args, &block) tc = Puppet::Pops::Types::TypeCalculator actual = tc.infer_set(block_given? ? args + [block] : args) found = @dispatchers.find { |d| tc.callable?(d.type, actual) } if found found.invoke(instance, calling_scope, args, &block) else raise ArgumentError, "function '#{instance.class.name}' called with mis-matched arguments\n#{Puppet::Pops::Evaluator::CallableMismatchDescriber.diff_string(instance.class.name, actual, @dispatchers)}" end end
Answers if dispatching has been defined @return [Boolean] true if dispatching has been defined
@api private
# File lib/puppet/pops/functions/dispatcher.rb, line 18 def empty? @dispatchers.empty? end
@api private
# File lib/puppet/pops/functions/dispatcher.rb, line 67 def signatures @dispatchers end
@api private
# File lib/puppet/pops/functions/dispatcher.rb, line 10 def initialize() @dispatchers = [ ] end