Module: ControllerMaker

Extended by:
Template
Defined in:
lib/umu/generators/controller_maker.rb

Overview

ControllerMaker is a module for generating controller.

Constant Summary collapse

ACTIONS =
%w[
  index
  show
  edit
  create
  update
  destroy
  other
].freeze

Constants included from Color

Color::COLORS

Class Method Summary collapse

Methods included from Template

checker, command, cover, hover, logo, pointer, show_command

Class Method Details

.generatorObject



21
22
23
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
62
# File 'lib/umu/generators/controller_maker.rb', line 21

def generator
  controller_name = Umu::Inputter.input(I18n.t('controller.make_name'))
  cover(1)
  show_command('controller', controller_name)
  make_actions = Umu::Selector.single_choice(I18n.t('controller.make_actions'))
  cover(1)
  actions = []
  if make_actions
    actions = Umu::Selector.checkbox(ACTIONS, I18n.t('controller.select_actions'))
    cover(1)
    cover(1)
    show_actions = actions.dup
    show_actions.delete('other')
    show_command('controller', controller_name, show_actions.join(' '))
    if actions.include?('other')
      make_action = true
      actions.delete('other')
      while make_action
        original_action_name = Umu::Inputter.input(I18n.t('controller.make_action_name'), true, actions)
        actions << original_action_name
        cover(2)
        show_command('controller', controller_name, actions.join(' '))
        make_action = Umu::Selector.single_choice(I18n.t('controller.make_action_continue'))
        cover(1)
      end
    end
  end
  is_make_options = Umu::Selector.single_choice(I18n.t('common.make_options'))
  options = ''
  cover(1)
  options = Umu::Inputter.input(I18n.t('common.add_option'), true) if is_make_options
  cover(1) if is_make_options
  command = command('controller', controller_name, actions.join(' '), options)
  cover(1)
  puts command
  confirm_content = I18n.t('common.run_command')
  run_command = Umu::Selector.single_choice(confirm_content)
  cover(1)
  puts confirm_content + (run_command ? I18n.t('affirm') : I18n.t('deny'))
  system(command) if run_command
  true
end