Class: GenerateModel

Inherits:
IRB::Command::Base
  • Object
show all
Defined in:
lib/alet/irb/command/generate_model.rb

Instance Method Summary collapse

Instance Method Details

#execute(arg) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/alet/irb/command/generate_model.rb', line 8

def execute(arg)
  pastel = Pastel.new
  argv = arg.split(' ')
  opt = OptionParser.new
  opt.parse!(argv)

  if argv.count.zero? || argv.first == 'list'
    if SObjectModel.generated_classes.empty?
      puts t('model.list.noclass')
      return
    end

    puts t('model.list.title')
    table =
      TTY::Table.new(rows: SObjectModel.generated_classes.each_slice(4).map{|row| row.map(&:name).append('','','','')[0..3]})
    puts table.render :basic
  elsif argv.first == 'load'
    SObjectModel.generate(*argv[1..-1])
  end
rescue SObjectModel::Rest::RequestError => e
  puts pastel.red(e.message)
rescue SObjectModel::Rest::RecordNotFoundError => e
  puts pastel.red(t('desc.error.notfound'))
end