Class: Puppet::Pal::FunctionSignature
- Defined in:
- lib/puppet/pal/function_signature.rb
Overview
A FunctionSignature is returned from ‘function_signature`. Its purpose is to answer questions about the function’s parameters and if it can be called with a set of parameters.
It is also possible to get an array of puppet Callable data type where each callable describes one possible way the function can be called.
Instance Method Summary collapse
-
#callable_with?(args, callable = nil) {|String| ... } ⇒ Boolean
Returns true if the function can be called with the given arguments and false otherwise.
-
#callables ⇒ Array<Puppet::Pops::Types::PCallableType] one callable per way the function can be called
Returns an array of Callable puppet data type.
-
#initialize(function_class) ⇒ FunctionSignature
constructor
private
A new instance of FunctionSignature.
Constructor Details
#initialize(function_class) ⇒ FunctionSignature
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 FunctionSignature.
15 16 17 |
# File 'lib/puppet/pal/function_signature.rb', line 15 def initialize(function_class) @func = function_class end |
Instance Method Details
#callable_with?(args, callable = nil) {|String| ... } ⇒ Boolean
Returns true if the function can be called with the given arguments and false otherwise. If the function is not callable, and a code block is given, it is given a formatted error message that describes the type mismatch. That error message can be quite complex if the function has multiple dispatch depending on given types.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/puppet/pal/function_signature.rb', line 30 def callable_with?(args, callable = nil) signatures = @func.dispatcher.to_type callables = signatures.is_a?(Puppet::Pops::Types::PVariantType) ? signatures.types : [signatures] return true if callables.any? { |t| t.callable_with?(args) } return false unless block_given? args_type = Puppet::Pops::Types::TypeCalculator.singleton.infer_set(callable.nil? ? args : args + [callable]) = Puppet::Pops::Types::TypeMismatchDescriber.describe_signatures(@func.name, @func.signatures, args_type) yield false end |
#callables ⇒ Array<Puppet::Pops::Types::PCallableType] one callable per way the function can be called
Returns an array of Callable puppet data type
48 49 50 51 |
# File 'lib/puppet/pal/function_signature.rb', line 48 def callables signatures = @func.dispatcher.to_type signatures.is_a?(Puppet::Pops::Types::PVariantType) ? signatures.types : [signatures] end |