Class: Tasker::Generators::TaskHandlerGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/tasker/task_handler_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_task_handler_filesObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/generators/tasker/task_handler_generator.rb', line 24

def create_task_handler_files
  # Set variables first
  @module_namespace = options[:module_namespace] || Tasker::Configuration.configuration.engine.default_module_namespace
  @module_path = @module_namespace&.underscore
  @task_handler_class = name.camelize
  @task_name = name.underscore
  @namespace_name = options[:namespace_name]
  @version = options[:version]
  @description = options[:description]
  @steps = options[:steps]

  # Load configuration
  ensure_configuration_loaded

  # Get directory paths from configuration
  @task_handler_directory = Tasker::Configuration.configuration.engine.task_handler_directory
  @task_config_directory = Tasker::Configuration.configuration.engine.task_config_directory

  # Ensure directories exist
  ensure_directories_exist(
    [
      task_handler_directory_with_module_path,
      spec_directory_with_module_path,
      task_config_directory_with_module_path
    ]
  )

  # Create the YAML config file
  template 'task_config.yaml.erb', "#{task_config_directory_with_module_path}/#{@task_name}.yaml"

  # Create the task handler class
  template 'task_handler.rb.erb', "#{task_handler_directory_with_module_path}/#{@task_name}.rb"

  # Create the task handler spec
  template 'task_handler_spec.rb.erb', "#{spec_directory_with_module_path}/#{@task_name}_spec.rb"

  display_success_message
end