Class: Bolt::Task
- Inherits:
-
Struct
- Object
- Struct
- Bolt::Task
- Defined in:
- lib/bolt/task.rb,
lib/bolt/task/puppet_server.rb
Overview
Represents a Task.
Direct Known Subclasses
Defined Under Namespace
Classes: PuppetServer
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#files ⇒ Object
Returns the value of attribute files.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#name ⇒ Object
Returns the value of attribute name.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
Instance Method Summary collapse
- #description ⇒ Object
-
#file_path(file_name) ⇒ Object
This provides a method we can override in subclasses if the ‘path’ needs to be fetched or computed.
- #implementations ⇒ Object
-
#initialize(task, remote: false) ⇒ Task
constructor
A new instance of Task.
- #module_name ⇒ Object
- #parameters ⇒ Object
- #remote_instance ⇒ Object
-
#select_implementation(target, provided_features = []) ⇒ Object
Returns a hash of implementation name, path to executable, input method (if defined), and any additional files (name and path).
- #supports_noop ⇒ Object
- #tasks_dir ⇒ Object
Constructor Details
#initialize(task, remote: false) ⇒ Task
Returns a new instance of Task.
26 27 28 29 30 31 32 |
# File 'lib/bolt/task.rb', line 26 def initialize(task, remote: false) super(nil, nil, [], {}) @remote = remote task.reject { |k, _| k == 'parameters' }.each { |k, v| self[k] = v } end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file
17 18 19 |
# File 'lib/bolt/task.rb', line 17 def file @file end |
#files ⇒ Object
Returns the value of attribute files
17 18 19 |
# File 'lib/bolt/task.rb', line 17 def files @files end |
#metadata ⇒ Object
Returns the value of attribute metadata
17 18 19 |
# File 'lib/bolt/task.rb', line 17 def @metadata end |
#name ⇒ Object
Returns the value of attribute name
17 18 19 |
# File 'lib/bolt/task.rb', line 17 def name @name end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
24 25 26 |
# File 'lib/bolt/task.rb', line 24 def remote @remote end |
Instance Method Details
#description ⇒ Object
38 39 40 |
# File 'lib/bolt/task.rb', line 38 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.
65 66 67 |
# File 'lib/bolt/task.rb', line 65 def file_path(file_name) file_map[file_name]['path'] end |
#implementations ⇒ Object
69 70 71 |
# File 'lib/bolt/task.rb', line 69 def implementations ['implementations'] end |
#module_name ⇒ Object
50 51 52 |
# File 'lib/bolt/task.rb', line 50 def module_name name.split('::').first end |
#parameters ⇒ Object
42 43 44 |
# File 'lib/bolt/task.rb', line 42 def parameters ['parameters'] end |
#remote_instance ⇒ Object
34 35 36 |
# File 'lib/bolt/task.rb', line 34 def remote_instance self.class.new(to_h.each_with_object({}) { |(k, v), h| h[k.to_s] = v }, remote: true) end |
#select_implementation(target, provided_features = []) ⇒ Object
Returns a hash of implementation name, path to executable, input method (if defined), and any additional files (name and path)
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/bolt/task.rb', line 75 def select_implementation(target, provided_features = []) impl = if (impls = implementations) available_features = target.features + provided_features impl = impls.find do |imp| remote_impl = imp['remote'] remote_impl = ['remote'] if remote_impl.nil? Set.new(imp['requirements']).subset?(available_features) && !!remote_impl == @remote end raise NoImplementationError.new(target, self) unless impl impl = impl.dup impl['path'] = file_path(impl['name']) impl.delete('requirements') impl else raise NoImplementationError.new(target, self) unless !!['remote'] == @remote 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_noop ⇒ Object
46 47 48 |
# File 'lib/bolt/task.rb', line 46 def supports_noop ['supports_noop'] end |
#tasks_dir ⇒ Object
54 55 56 |
# File 'lib/bolt/task.rb', line 54 def tasks_dir File.join(module_name, 'tasks') end |