Class: Wicked::Pipeline::ControllerGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Generators::Helpers
Defined in:
lib/generators/wicked/pipeline/controller/controller_generator.rb

Instance Method Summary collapse

Methods included from Generators::Helpers

#available_locales, #hashify_locale_keypath, #indented, #options_as_switches, #remove_possible_suffix

Instance Method Details

#add_routesObject



48
49
50
51
52
53
54
# File 'lib/generators/wicked/pipeline/controller/controller_generator.rb', line 48

def add_routes
  return if options[:skip_routes]

  routing_code = "resources :#{file_name}_steps, only: [:show, :update], param: :#{resource_param_name}"

  route routing_code, namespace: regular_class_path
end

#create_controller_filesObject



24
25
26
# File 'lib/generators/wicked/pipeline/controller/controller_generator.rb', line 24

def create_controller_files
  template "controller.rb", File.join("app/controllers", class_path, "#{file_name}_steps_controller.rb")
end

#create_locale_fileObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/generators/wicked/pipeline/controller/controller_generator.rb', line 37

def create_locale_file
  return if options[:skip_locales]

  @structure = hashify_locale_keypath([*class_path, "#{file_name}_steps"].join("."))

  available_locales.each do |locale|
    @locale = locale
    template "locale.yml", File.join("config/locales/views", class_path, "#{file_name}_steps.#{locale}.yml")
  end
end

#create_pipeline_fileObject



56
57
58
59
60
61
62
63
64
# File 'lib/generators/wicked/pipeline/controller/controller_generator.rb', line 56

def create_pipeline_file
  return unless options[:generate_pipeline]

  pipeline_args = [pipeline]
  pipeline_args.concat(steps) if options[:generate_steps]
  pipeline_args.concat(options_as_switches)

  Rails::Generators.invoke "wicked:pipeline", pipeline_args, behavior: behavior
end

#create_step_filesObject



66
67
68
69
70
71
72
# File 'lib/generators/wicked/pipeline/controller/controller_generator.rb', line 66

def create_step_files
  return if options[:generate_pipeline] || !options[:generate_steps]

  steps.each do |step|
    Rails::Generators.invoke "wicked:pipeline:step", [step, *options_as_switches], behavior: behavior
  end
end