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

new(task) click to toggle source
  # File lib/puppet/pal/task_signature.rb
7 def initialize(task)
8   @task = task
9 end

Public Instance Methods

runnable_with?(args_hash) { |"Task #{name}:\n#{error}"| ... } click to toggle source

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
20 def runnable_with?(args_hash)
21   params = @task.parameters
22   params_type = if params.nil?
23     T_GENERIC_TASK_HASH
24   else
25     Puppet::Pops::Types::TypeFactory.struct(params)
26   end
27   return true if params_type.instance?(args_hash)
28 
29   if block_given?
30     tm = Puppet::Pops::Types::TypeMismatchDescriber.singleton
31     error = if params.nil?
32       tm.describe_mismatch('', params_type, Puppet::Pops::Types::TypeCalculator.infer_set(args_hash))
33     else
34       tm.describe_struct_signature(params_type, args_hash).flatten.map {|e| e.format }.join("\n")
35     end
36     yield "Task #{@task.name}:\n#{error}"
37   end
38   false
39 end
task() click to toggle source

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
52 def task
53   @task
54 end
task_hash() click to toggle source

Returns the Task instance as a hash

@return [Hash{String=>Object}] the hash representation of the task

   # File lib/puppet/pal/task_signature.rb
44 def task_hash
45   @task._pcore_init_hash
46 end