Class: DeployPin::TaskGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/deploy_pin/task/task_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ TaskGenerator

Returns a new instance of TaskGenerator.



16
17
18
19
20
# File 'lib/generators/deploy_pin/task/task_generator.rb', line 16

def initialize(*args)
  super

  validate
end

Instance Method Details

#create_task_fileObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/deploy_pin/task/task_generator.rb', line 22

def create_task_file
  template_file = if options[:parallel]
                    'parallel_task.rb.erb'
                  else
                    'task.rb.erb'
                  end

  @author = options[:author] || ENV['USER']
  @group = options[:group]
  @recurring = options[:recurring]
  @identifier = @recurring ? options[:identifier] : Time.now.strftime('%Y%m%d%H%M%S')
  filename = @recurring ? "r_#{@identifier}_#{title}.rb" : "#{@identifier}_#{title}.rb"
  template template_file, "#{DeployPin.tasks_path}/#{filename}"
end

#validateObject

Raises:

  • (Thor::Error)


37
38
39
40
41
42
43
# File 'lib/generators/deploy_pin/task/task_generator.rb', line 37

def validate
  raise Thor::Error, set_color('Missing required option: --group', :red) if options[:group].blank?

  return if DeployPin.groups.include?(options[:group])

  raise Thor::Error, set_color("Group '#{options[:group]}' is not defined in DeployPin.groups", :red)
end