class Puppet::Pops::Functions::Dispatcher
Evaluate the dispatches defined as {Puppet::Pops::Functions::Dispatch} instances to call the appropriate method on the {Puppet::Pops::Functions::Function} instance.
@api private
Attributes
dispatchers[R]
Public Class Methods
new()
click to toggle source
@api private
# File lib/puppet/pops/functions/dispatcher.rb 11 def initialize() 12 @dispatchers = [ ] 13 end
Public Instance Methods
add(a_dispatch)
click to toggle source
Adds a dispatch directly to the set of dispatchers. @api private
# File lib/puppet/pops/functions/dispatcher.rb 54 def add(a_dispatch) 55 @dispatchers << a_dispatch 56 end
dispatch(instance, calling_scope, args, &block)
click to toggle source
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 35 def dispatch(instance, calling_scope, args, &block) 36 37 dispatcher = find_matching_dispatcher(args, &block) 38 unless dispatcher 39 args_type = Puppet::Pops::Types::TypeCalculator.singleton.infer_set(block_given? ? args + [block] : args) 40 raise ArgumentError, Puppet::Pops::Types::TypeMismatchDescriber.describe_signatures(instance.class.name, signatures, args_type) 41 end 42 if dispatcher.argument_mismatch_handler? 43 msg = dispatcher.invoke(instance, calling_scope, args) 44 raise ArgumentError, "'#{instance.class.name}' #{msg}" 45 end 46 47 catch(:next) do 48 dispatcher.invoke(instance, calling_scope, args, &block) 49 end 50 end
empty?()
click to toggle source
Answers if dispatching has been defined @return [Boolean] true if dispatching has been defined
@api private
# File lib/puppet/pops/functions/dispatcher.rb 19 def empty? 20 @dispatchers.empty? 21 end
find_matching_dispatcher(args, &block)
click to toggle source
# File lib/puppet/pops/functions/dispatcher.rb 23 def find_matching_dispatcher(args, &block) 24 @dispatchers.find { |d| d.type.callable_with?(args, block) } 25 end
signatures()
click to toggle source
@api private
# File lib/puppet/pops/functions/dispatcher.rb 73 def signatures 74 @dispatchers.reject { |dispatcher| dispatcher.argument_mismatch_handler? } 75 end
to_type()
click to toggle source