Class: Puppet::Pal::ScriptCompiler

Inherits:
Compiler show all
Defined in:
lib/puppet/pal/script_compiler.rb

Instance Method Summary collapse

Methods inherited from Compiler

#call_function, #create, #evaluate, #evaluate_file, #evaluate_literal, #evaluate_string, #function_signature, #has_catalog?, #initialize, #list_functions, #parse_file, #parse_string, #type

Constructor Details

This class inherits a constructor from Puppet::Pal::Compiler

Instance Method Details

#list_plans(filter_regex = nil, error_collector = nil) ⇒ Array<Puppet::Pops::Loader::TypedName>

Returns an array of TypedName objects for all plans, optionally filtered by a regular expression. The returned array has more information than just the leaf name - the typical thing is to just get the name as showing the following example.

Errors that occur during plan discovery will either be logged as warnings or collected by the optional ‘error_collector` array. When provided, it will receive DataTypes::Error instances describing each error in detail and no warnings will be logged.

Examples:

getting the names of all plans

compiler.list_plans.map {|tn| tn.name }

Parameters:

  • filter_regex (Regexp) (defaults to: nil)

    an optional regexp that filters based on name (matching names are included in the result)

  • error_collector (Array<Puppet::DataTypes::Error>) (defaults to: nil)

    an optional array that will receive errors during load

Returns:



36
37
38
# File 'lib/puppet/pal/script_compiler.rb', line 36

def list_plans(filter_regex = nil, error_collector = nil)
  list_loadable_kind(:plan, filter_regex, error_collector)
end

#list_tasks(filter_regex = nil, error_collector = nil) ⇒ Array<Puppet::Pops::Loader::TypedName>

Returns an array of TypedName objects for all tasks, optionally filtered by a regular expression. The returned array has more information than just the leaf name - the typical thing is to just get the name as showing the following example.

Errors that occur during task discovery will either be logged as warnings or collected by the optional ‘error_collector` array. When provided, it will receive DataTypes::Error instances describing each error in detail and no warnings will be logged.

Examples:

getting the names of all tasks

compiler.list_tasks.map {|tn| tn.name }

Parameters:

  • filter_regex (Regexp) (defaults to: nil)

    an optional regexp that filters based on name (matching names are included in the result)

  • error_collector (Array<Puppet::DataTypes::Error>) (defaults to: nil)

    an optional array that will receive errors during load

Returns:



70
71
72
# File 'lib/puppet/pal/script_compiler.rb', line 70

def list_tasks(filter_regex = nil, error_collector = nil)
  list_loadable_kind(:task, filter_regex, error_collector)
end

#plan_signature(plan_name) ⇒ Puppet::Pal::PlanSignature?

Returns the signature of the given plan name

Parameters:

  • plan_name (String)

    the name of the plan to get the signature of

Returns:



10
11
12
13
14
15
16
17
18
19
# File 'lib/puppet/pal/script_compiler.rb', line 10

def plan_signature(plan_name)
  loader = internal_compiler.loaders.private_environment_loader
  func = loader.load(:plan, plan_name)
  if func
    return PlanSignature.new(func)
  end

  # Could not find plan
  nil
end

#task_signature(task_name) ⇒ Puppet::Pal::TaskSignature?

Returns the signature callable of the given task (the arguments it accepts, and the data type it returns)

Parameters:

  • task_name (String)

    the name of the task to get the signature of

Returns:



44
45
46
47
48
49
50
51
52
53
# File 'lib/puppet/pal/script_compiler.rb', line 44

def task_signature(task_name)
  loader = internal_compiler.loaders.private_environment_loader
  task = loader.load(:task, task_name)
  if task
    return TaskSignature.new(task)
  end

  # Could not find task
  nil
end