class Puppet::Pal::TaskSignature
A TaskSignature is returned from `task_signature`. Its purpose is to answer questions about the task's parameters and if it can be run/called with a hash of named parameters.
Public Class Methods
# File lib/puppet/pal/task_signature.rb 8 def initialize(task) 9 @task = task 10 end
Public Instance Methods
Returns whether or not the given arguments are acceptable when running the task. In addition to returning the boolean outcome, if a block is given, it is called with a string of formatted error messages that describes the difference between what was given and what is expected. The error message may have multiple lines of text, and each line is indented one space.
@param args_hash [Hash] a hash mapping parameter names to argument values @yieldparam [String] a formatted error message if a type mismatch occurs that explains the mismatch @return [Boolean] if the given arguments are acceptable when running the task
# File lib/puppet/pal/task_signature.rb 21 def runnable_with?(args_hash) 22 params = @task.parameters 23 params_type = if params.nil? 24 T_GENERIC_TASK_HASH 25 else 26 Puppet::Pops::Types::TypeFactory.struct(params) 27 end 28 return true if params_type.instance?(args_hash) 29 30 if block_given? 31 tm = Puppet::Pops::Types::TypeMismatchDescriber.singleton 32 error = if params.nil? 33 tm.describe_mismatch('', params_type, Puppet::Pops::Types::TypeCalculator.infer_set(args_hash)) 34 else 35 tm.describe_struct_signature(params_type, args_hash).flatten.map {|e| e.format }.join("\n") 36 end 37 yield "Task #{@task.name}:\n#{error}" 38 end 39 false 40 end
Returns the Task instance which can be further explored. It contains all meta-data defined for the task such as the description, parameters, output, etc.
@return [Puppet::Pops::Types::PuppetObject] An instance of a dynamically created Task class
# File lib/puppet/pal/task_signature.rb 53 def task 54 @task 55 end
Returns the Task instance as a hash
@return [Hash{String=>Object}] the hash representation of the task
# File lib/puppet/pal/task_signature.rb 45 def task_hash 46 @task._pcore_init_hash 47 end