Class: Puppet::Pops::Functions::Dispatcher Private
- Defined in:
- lib/puppet/pops/functions/dispatcher.rb
Overview
Instance Attribute Summary collapse
- #dispatchers ⇒ Object readonly private
Instance Method Summary collapse
-
#add(a_dispatch) ⇒ Object
private
Adds a dispatch directly to the set of dispatchers.
-
#dispatch(instance, calling_scope, args, &block) ⇒ Object
private
Dispatches the call to the first found signature (entry with matching type).
-
#empty? ⇒ Boolean
private
Answers if dispatching has been defined.
- #find_matching_dispatcher(args, &block) ⇒ Object private
-
#initialize ⇒ Dispatcher
constructor
private
A new instance of Dispatcher.
- #signatures ⇒ Object private
-
#to_type ⇒ Object
private
Produces a CallableType for a single signature, and a Variant otherwise.
Constructor Details
#initialize ⇒ Dispatcher
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Dispatcher.
12 13 14 |
# File 'lib/puppet/pops/functions/dispatcher.rb', line 12 def initialize @dispatchers = [] end |
Instance Attribute Details
#dispatchers ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/puppet/pops/functions/dispatcher.rb', line 9 def dispatchers @dispatchers end |
Instance Method Details
#add(a_dispatch) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Adds a dispatch directly to the set of dispatchers.
54 55 56 |
# File 'lib/puppet/pops/functions/dispatcher.rb', line 54 def add(a_dispatch) @dispatchers << a_dispatch end |
#dispatch(instance, calling_scope, args, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Dispatches the call to the first found signature (entry with matching type).
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/puppet/pops/functions/dispatcher.rb', line 36 def dispatch(instance, calling_scope, args, &block) dispatcher = find_matching_dispatcher(args, &block) unless dispatcher args_type = Puppet::Pops::Types::TypeCalculator.singleton.infer_set(block_given? ? args + [block] : args) raise ArgumentError, Puppet::Pops::Types::TypeMismatchDescriber.describe_signatures(instance.class.name, signatures, args_type) end if dispatcher.argument_mismatch_handler? msg = dispatcher.invoke(instance, calling_scope, args) raise ArgumentError, "'#{instance.class.name}' #{msg}" end catch(:next) do dispatcher.invoke(instance, calling_scope, args, &block) end end |
#empty? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Answers if dispatching has been defined
20 21 22 |
# File 'lib/puppet/pops/functions/dispatcher.rb', line 20 def empty? @dispatchers.empty? end |
#find_matching_dispatcher(args, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
24 25 26 |
# File 'lib/puppet/pops/functions/dispatcher.rb', line 24 def find_matching_dispatcher(args, &block) @dispatchers.find { |d| d.type.callable_with?(args, block) } end |
#signatures ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
73 74 75 |
# File 'lib/puppet/pops/functions/dispatcher.rb', line 73 def signatures @dispatchers.reject(&:argument_mismatch_handler?) end |
#to_type ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Produces a CallableType for a single signature, and a Variant otherwise
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/puppet/pops/functions/dispatcher.rb', line 61 def to_type # make a copy to make sure it can be contained by someone else (even if it is not contained here, it # should be treated as immutable). # callables = dispatchers.map(&:type) # multiple signatures, produce a Variant type of Callable1-n (must copy them) # single signature, produce single Callable callables.size > 1 ? Puppet::Pops::Types::TypeFactory.variant(*callables) : callables.pop end |