class MaintenanceTasks::TaskGenerator

Generator used for creating maintenance tasks in the host application.

@api private

Public Instance Methods

create_task_file() click to toggle source

Creates the Task file.

# File lib/generators/maintenance_tasks/task_generator.rb, line 18
def create_task_file
  template_file = File.join(
    "app/tasks/#{tasks_module_file_path}",
    class_path,
    "#{file_name}_task.rb"
  )
  if options[:csv]
    template("csv_task.rb", template_file)
  else
    template("task.rb", template_file)
  end
end
create_test_file() click to toggle source

Creates the Task test file, according to the app's test framework. A spec file is created if the app uses RSpec. Otherwise, an ActiveSupport::TestCase test is created.

# File lib/generators/maintenance_tasks/task_generator.rb, line 34
def create_test_file
  return unless test_framework

  if test_framework == :rspec
    create_task_spec_file
  else
    create_task_test_file
  end
end

Private Instance Methods

create_task_spec_file() click to toggle source
# File lib/generators/maintenance_tasks/task_generator.rb, line 55
def create_task_spec_file
  template_file = File.join(
    "spec/tasks/#{tasks_module_file_path}",
    class_path,
    "#{file_name}_task_spec.rb"
  )
  template("task_spec.rb", template_file)
end
create_task_test_file() click to toggle source
# File lib/generators/maintenance_tasks/task_generator.rb, line 46
def create_task_test_file
  template_file = File.join(
    "test/tasks/#{tasks_module_file_path}",
    class_path,
    "#{file_name}_task_test.rb"
  )
  template("task_test.rb", template_file)
end
file_name() click to toggle source
Calls superclass method
# File lib/generators/maintenance_tasks/task_generator.rb, line 64
def file_name
  super.sub(/_task\z/i, "")
end
tasks_module() click to toggle source
# File lib/generators/maintenance_tasks/task_generator.rb, line 68
def tasks_module
  MaintenanceTasks.tasks_module
end
tasks_module_file_path() click to toggle source
# File lib/generators/maintenance_tasks/task_generator.rb, line 72
def tasks_module_file_path
  tasks_module.underscore
end
test_framework() click to toggle source
# File lib/generators/maintenance_tasks/task_generator.rb, line 76
def test_framework
  Rails.application.config.generators.options[:rails][:test_framework]
end