Class: Steroid::ControllerGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/steroid/controller/controller_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_controllerObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/generators/steroid/controller/controller_generator.rb', line 10

def add_controller
  say "Applying steroid: Controller", [:bold, :magenta]
  cmd = ["rails generate controller"]
  prompt = TTY::Prompt.new
  controller_name = prompt.ask("\nWhat is the great name of your controller?") do |q|
    q.required true
    q.modify :remove
  end
  cmd << controller_name

  actions = prompt.multi_select("\nChoose actions:", %w(index show new edit create update destroy))
  cmd += actions

  boolean_choices = [{name: "yes", value: true}, {name: "no", value: false}]

  custom_actions = []
  while prompt.select("\nWould you like to add more actions?", boolean_choices)
    custom_actions << prompt.ask("Specify name of action:") do |q|
      q.required true
      q.modify :remove
    end
  end
  cmd += custom_actions

  cmd << "--skip-routes" if prompt.select("\nSkip routes?", boolean_choices)
  cmd << "--no-helper" if prompt.select("\nSkip helper?", boolean_choices)

  run cmd.join(" ")
end