Class: Puppet::Pops::Functions::Dispatch Private
- Inherits:
-
Evaluator::CallableSignature
- Object
- Evaluator::CallableSignature
- Puppet::Pops::Functions::Dispatch
- Defined in:
- lib/puppet/pops/functions/dispatch.rb
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.
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
- #argument_mismatch_handler? ⇒ Boolean private
-
#initialize(type, method_name, param_names, last_captures = false, block_name = nil, injections = EMPTY_ARRAY, weaving = EMPTY_ARRAY, argument_mismatch_handler = false) ⇒ 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, last_captures = false, block_name = nil, injections = EMPTY_ARRAY, weaving = EMPTY_ARRAY, argument_mismatch_handler = false) ⇒ 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.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 35 def initialize(type, method_name, param_names, last_captures = false, block_name = nil, injections = EMPTY_ARRAY, weaving = EMPTY_ARRAY, argument_mismatch_handler = false) @type = type @method_name = method_name @param_names = param_names @last_captures = last_captures @block_name = block_name @injections = injections @weaving = weaving @argument_mismatch_handler = argument_mismatch_handler end |
Instance Attribute Details
#block_name ⇒ Object (readonly)
24 25 26 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 24 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.
17 18 19 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 17 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
16 17 18 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 16 def param_names @param_names end |
#type ⇒ Object (readonly)
14 15 16 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 14 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.
22 23 24 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 22 def weaving @weaving end |
Instance Method Details
#argument_mismatch_handler? ⇒ 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.
56 57 58 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 56 def argument_mismatch_handler? @argument_mismatch_handler end |
#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.
61 62 63 64 65 66 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 61 def invoke(instance, calling_scope, args, &block) result = instance.send(@method_name, *weave(calling_scope, args), &block) return_type = @type.return_type Types::TypeAsserter.assert_instance_of(nil, return_type, result) { "value returned from function '#{@method_name}'" } unless return_type.nil? result 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.
52 53 54 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 52 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.
47 48 49 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 47 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.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/puppet/pops/functions/dispatch.rb', line 69 def weave(scope, args) # no need to weave if there are no injections if @injections.empty? args else new_args = [] @weaving.each do |knit| if knit.is_a?(Array) injection_name = @injections[knit[0]] new_args << case injection_name when :scope scope when :pal_script_compiler Puppet.lookup(:pal_script_compiler) when :cache Puppet::Pops::Adapters::ObjectIdCacheAdapter.adapt(scope.compiler) when :pal_catalog_compiler Puppet.lookup(:pal_catalog_compiler) when :pal_compiler Puppet.lookup(:pal_compiler) else raise ArgumentError, _("Unknown injection %{injection_name}") % { injection_name: injection_name } end elsif knit < 0 # Careful so no new nil arguments are added since they would override default # parameter values in the received idx = -knit - 1 new_args += args[idx..] if idx < args.size elsif knit < args.size new_args << args[knit] end end new_args end end |