Module: ModelMaker

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

Overview

ModelMaker is a module for generating model.

Constant Summary collapse

COLUMN_TYPE =
%w[
  string
  text
  integer
  float
  decimal
  datetime
  timestamp
  time
  date
  binary
  boolean
  primary_key
].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



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
# File 'lib/umu/generators/model_maker.rb', line 26

def generator
  model_name = Umu::Inputter.input(I18n.t('model.make_name'))
  cover(1)
  show_command('model', model_name)
  is_make_column = Umu::Selector.single_choice(I18n.t('model.make_column'))
  cover(1)
  columns = []
  while is_make_column
    columns << make_column
    show_command('model', model_name, columns.join(' '))
    is_make_column = Umu::Selector.single_choice(I18n.t('model.make_column_continue'))
    cover(1)
  end

  show_command('model', model_name, columns.join(' '))
  cover(1)
  is_make_options = Umu::Selector.single_choice(I18n.t('common.make_options'))
  cover(1)
  options = ''
  options = Umu::Inputter.input(I18n.t('common.add_option'), true) if is_make_options
  cover(1) if is_make_options

  command = command('model', model_name, columns.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

.make_columnObject



59
60
61
62
63
64
65
# File 'lib/umu/generators/model_maker.rb', line 59

def make_column
  colum_name = Umu::Inputter.input(I18n.t('model.make_column_name'))
  cover(1)
  type = Umu::Selector.radio(COLUMN_TYPE, I18n.t('model.choose_column_type'))
  cover(2)
  "#{colum_name}:#{type}"
end