Class: Puppet::Pops::Loader::TaskInstantiator

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/loader/task_instantiator.rb

Class Method Summary collapse

Class Method Details

.create(loader, typed_name, source_refs) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/puppet/pops/loader/task_instantiator.rb', line 9

def self.create(loader, typed_name, source_refs)
  name = typed_name.name
  basename = typed_name.name_parts[1] || 'init'
  dirname = File.dirname(source_refs[0])
  , executables = source_refs.partition { |source_ref| source_ref.end_with?('.json') }
   = .find { |source_ref| File.basename(source_ref, '.json') == basename }

   = Puppet::Module::Task.() || {}

  files = Puppet::Module::Task.find_files(name, dirname, , executables)

  task = { 'name' => name, 'metadata' => , 'files' => files }

  begin
    unless ['parameters'].is_a?(Hash) || ['parameters'].nil?
      msg = _('Failed to load metadata for task %{name}: \'parameters\' must be a hash') % { name: name }
      raise Puppet::ParseError.new(msg, )
    end
    task['parameters'] = convert_types(['parameters'])

    Types::TypeFactory.task.from_hash(task)
  rescue Types::TypeAssertionError => ex
    # Not strictly a parser error but from the users perspective, the file content didn't parse properly. The
    # ParserError also conveys file info (even though line is unknown)
    msg = _('Failed to load metadata for task %{name}: %{reason}') % { name: name, reason: ex.message }
    raise Puppet::ParseError.new(msg, )
  end
end