Class: Interactive::ModelGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/interactive/model/model_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_modelObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/interactive/model/model_generator.rb', line 15

def add_model
  say "Starting interactive Model generator", [:bold, :magenta]
  cmd = ["rails #{self.behavior == :invoke ? 'generate' : 'destroy'} model"]

  model_name = prompt.ask("\nWhat is the great name of your model?", required: true) { |q| q.modify :remove }
  cmd << model_name

  if prompt.select("\nSkip migration?", boolean_choices)
    cmd << "--no-migration"
  else
    cmd += select_columns_configuration
    cmd << "--no-timestamps" if prompt.select("\nSkip created_at, updated_at timestamps?", boolean_choices)
    cmd << "--no-indexes" if prompt.select("\nSkip indexes?", boolean_choices)
  end

  run cmd.join(" ")
end

#helpObject



8
9
10
11
12
13
# File 'lib/generators/interactive/model/model_generator.rb', line 8

def help
  if ['-h', 'help', '--help'].include?(ARGV.last)
    puts File.read("#{__dir__}/USAGE")
    exit
  end
end