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 10 def initialize() 11 @dispatchers = [ ] 12 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 49 def add(a_dispatch) 50 @dispatchers << a_dispatch 51 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 30 def dispatch(instance, calling_scope, args, &block) 31 found = @dispatchers.find { |d| d.type.callable_with?(args, block) } 32 unless found 33 args_type = Puppet::Pops::Types::TypeCalculator.singleton.infer_set(block_given? ? args + [block] : args) 34 raise ArgumentError, Puppet::Pops::Types::TypeMismatchDescriber.describe_signatures(instance.class.name, signatures, args_type) 35 end 36 37 if found.argument_mismatch_handler? 38 msg = found.invoke(instance, calling_scope, args) 39 raise ArgumentError, "'#{instance.class.name}' #{msg}" 40 end 41 42 catch(:next) do 43 found.invoke(instance, calling_scope, args, &block) 44 end 45 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 18 def empty? 19 @dispatchers.empty? 20 end
signatures()
click to toggle source
@api private
# File lib/puppet/pops/functions/dispatcher.rb 68 def signatures 69 @dispatchers.reject { |dispatcher| dispatcher.argument_mismatch_handler? } 70 end
to_type()
click to toggle source