Class: PDK::Generate::Task

Inherits:
PuppetObject show all
Defined in:
lib/pdk/generate/task.rb

Instance Attribute Summary

Attributes inherited from PuppetObject

#context, #object_name, #options

Instance Method Summary collapse

Methods inherited from PuppetObject

#can_run?, #initialize, #module_name, #run, #spec_only?, #stage_change, #stage_changes, #templates, #update_manager_instance, #with_templates

Constructor Details

This class inherits a constructor from PDK::Generate::PuppetObject

Instance Method Details

#check_preconditionsObject

Checks that the task has not already been defined with a different extension.

task exist in the <module>/tasks/ directory

Raises:



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pdk/generate/task.rb', line 28

def check_preconditions
  super

  error = _("A task named '%{name}' already exists in this module; defined in %{file}")
  allowed_extensions = %w[.md .conf]

  PDK::Util::Filesystem.glob(File.join(context.root_path, 'tasks', task_name + '.*')).each do |file|
    next if allowed_extensions.include?(File.extname(file))

    raise PDK::CLI::ExitWithError, error % { name: task_name, file: file }
  end
end

#friendly_nameObject



6
7
8
# File 'lib/pdk/generate/task.rb', line 6

def friendly_name
  'Task'
end

#non_template_filesObject



41
42
43
44
# File 'lib/pdk/generate/task.rb', line 41

def non_template_files
   = File.join('tasks', task_name + '.json')
  {  => JSON.pretty_generate() }
end

#template_dataObject



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

def template_data
  {
    name: object_name,
  }
end

#template_filesObject



10
11
12
13
14
15
# File 'lib/pdk/generate/task.rb', line 10

def template_files
  return {} if spec_only?
  {
    'task.erb' => File.join('tasks', task_name + '.sh'),
  }
end