Class: Puppet::Pops::Functions::Dispatch Private
- Inherits:
-
Evaluator::CallableSignature
- Object
- Evaluator::CallableSignature
- Puppet::Pops::Functions::Dispatch
- Defined in:
- lib/puppet/pops/functions/dispatch.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defines a connection between a implementation method and the signature that the method will handle.
This interface should not be used directly. Instead dispatches should be constructed using the DSL defined in Functions.
Instance Attribute Summary collapse
- #block_name ⇒ Object readonly
- #injections ⇒ Object readonly private
-
#param_names ⇒ Object
readonly
private
TODO: refactor to parameter_names since that makes it API.
- #type ⇒ Object readonly
-
#weaving ⇒ Object
readonly
private
Describes how arguments are woven if there are injections, a regular argument is a given arg index, an array an injection description.
Instance Method Summary collapse
-
#initialize(type, method_name, param_names, block_name, injections, weaving, last_captures) ⇒ Dispatch
constructor
private
A new instance of Dispatch.
- #invoke(instance, calling_scope, args, &block) ⇒ Object private
- #last_captures_rest? ⇒ Boolean private
- #parameter_names ⇒ Object private
- #weave(scope, args) ⇒ Object private
Methods inherited from Evaluator::CallableSignature
#args_range, #block_range, #block_type, #infinity?
Constructor Details
#initialize(type, method_name, param_names, block_name, injections, weaving, last_captures) ⇒ Dispatch
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 Dispatch.
23 24 25 26 27 28 29 30 31 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 23 def initialize(type, method_name, param_names, block_name, injections, weaving, last_captures) @type = type @method_name = method_name @param_names = param_names || [] @block_name = block_name @injections = injections || [] @weaving = weaving @last_captures = last_captures end |
Instance Attribute Details
#block_name ⇒ Object (readonly)
20 21 22 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 20 def block_name @block_name end |
#injections ⇒ 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.
13 14 15 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 13 def injections @injections end |
#param_names ⇒ 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.
TODO: refactor to parameter_names since that makes it API
12 13 14 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 12 def param_names @param_names end |
#type ⇒ Object (readonly)
10 11 12 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 10 def type @type end |
#weaving ⇒ 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.
Describes how arguments are woven if there are injections, a regular argument is a given arg index, an array an injection description.
18 19 20 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 18 def weaving @weaving end |
Instance Method Details
#invoke(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.
44 45 46 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 44 def invoke(instance, calling_scope, args, &block) instance.send(@method_name, *weave(calling_scope, args), &block) end |
#last_captures_rest? ⇒ 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.
39 40 41 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 39 def last_captures_rest? !! @last_captures end |
#parameter_names ⇒ 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.
34 35 36 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 34 def parameter_names @param_names end |
#weave(scope, args) ⇒ 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.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 49 def weave(scope, args) # no need to weave if there are no injections if @injections.empty? args else injector = nil # lazy lookup of injector Puppet.lookup(:injector) new_args = [] @weaving.each do |knit| if knit.is_a?(Array) injection_data = @injections[knit[0]] new_args << case injection_data[3] when :dispatcher_internal # currently only supports :scope injection scope when :producer injector ||= Puppet.lookup(:injector) injector.lookup_producer(scope, injection_data[0], injection_data[2]) else injector ||= Puppet.lookup(:injector) injector.lookup(scope, injection_data[0], injection_data[2]) end else # Careful so no new nil arguments are added since they would override default # parameter values in the received if knit < 0 idx = -knit - 1 new_args += args[idx..-1] if idx < args.size else new_args << args[knit] if knit < args.size end end end new_args end end |