Class: Bolt::Task

Inherits:
Struct
  • Object
show all
Defined in:
lib/bolt/task.rb,
lib/bolt/task/puppet_server.rb

Overview

Represents a Task.

Direct Known Subclasses

PuppetServer

Defined Under Namespace

Classes: PuppetServer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task) ⇒ Task

Returns a new instance of Task.



17
18
19
20
21
# File 'lib/bolt/task.rb', line 17

def initialize(task)
  super(nil, nil, [], {})

  task.reject { |k, _| k == 'parameters' }.each { |k, v| self[k] = v }
end

Instance Attribute Details

#fileObject

Returns the value of attribute file

Returns:

  • (Object)

    the current value of file



10
11
12
# File 'lib/bolt/task.rb', line 10

def file
  @file
end

#filesObject

Returns the value of attribute files

Returns:

  • (Object)

    the current value of files



10
11
12
# File 'lib/bolt/task.rb', line 10

def files
  @files
end

#metadataObject

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



10
11
12
# File 'lib/bolt/task.rb', line 10

def 
  
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



10
11
12
# File 'lib/bolt/task.rb', line 10

def name
  @name
end

Instance Method Details

#descriptionObject



23
24
25
# File 'lib/bolt/task.rb', line 23

def description
  ['description']
end

#file_path(file_name) ⇒ Object

This provides a method we can override in subclasses if the ‘path’ needs to be fetched or computed.



50
51
52
# File 'lib/bolt/task.rb', line 50

def file_path(file_name)
  file_map[file_name]['path']
end

#module_nameObject



35
36
37
# File 'lib/bolt/task.rb', line 35

def module_name
  name.split('::').first
end

#parametersObject



27
28
29
# File 'lib/bolt/task.rb', line 27

def parameters
  ['parameters']
end

#select_implementation(target, additional_features = []) ⇒ Object

Returns a hash of implementation name, path to executable, input method (if defined), and any additional files (name and path)



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/bolt/task.rb', line 56

def select_implementation(target, additional_features = [])
  impl = if (impls = ['implementations'])
           available_features = target.features + additional_features
           impl = impls.find { |imp| Set.new(imp['requirements']).subset?(available_features) }
           raise "No suitable implementation of #{name} for #{target.name}" unless impl
           impl = impl.dup
           impl['path'] = file_path(impl['name'])
           impl.delete('requirements')
           impl
         else
           name = files.first['name']
           { 'name' => name, 'path' => file_path(name) }
         end

  inmethod = impl['input_method'] || ['input_method']
  impl['input_method'] = inmethod unless inmethod.nil?

  mfiles = impl.fetch('files', []) + .fetch('files', [])
  dirnames, filenames = mfiles.partition { |file| file.end_with?('/') }
  impl['files'] = filenames.map do |file|
    path = file_path(file)
    raise "No file found for reference #{file}" if path.nil?
    { 'name' => file, 'path' => path }
  end

  unless dirnames.empty?
    files.each do |file|
      name = file['name']
      if dirnames.any? { |dirname| name.start_with?(dirname) }
        impl['files'] << { 'name' => name, 'path' => file_path(name) }
      end
    end
  end

  impl
end

#supports_noopObject



31
32
33
# File 'lib/bolt/task.rb', line 31

def supports_noop
  ['supports_noop']
end

#tasks_dirObject



39
40
41
# File 'lib/bolt/task.rb', line 39

def tasks_dir
  File.join(module_name, 'tasks')
end