Class: BulletTrain::SuperScaffolding::Scaffolders::CrudFieldScaffolder

Inherits:
BulletTrain::SuperScaffolding::Scaffolder show all
Defined in:
lib/bullet_train/super_scaffolding/scaffolders/crud_field_scaffolder.rb

Instance Attribute Summary

Attributes inherited from BulletTrain::SuperScaffolding::Scaffolder

#argv

Instance Method Summary collapse

Methods inherited from BulletTrain::SuperScaffolding::Scaffolder

#initialize

Constructor Details

This class inherits a constructor from BulletTrain::SuperScaffolding::Scaffolder

Instance Method Details

#runObject



5
6
7
8
9
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
39
# File 'lib/bullet_train/super_scaffolding/scaffolders/crud_field_scaffolder.rb', line 5

def run
  unless argv.count >= 2
    puts ""
    puts "🚅  usage: bin/super-scaffold crud-field <Model> <attribute:type> <attribute:type> ... [options]"
    puts ""
    puts "E.g. add a description and body to Pages:"
    puts "  bin/super-scaffold crud-field Page description:text_area body:text_area"
    puts ""
    puts "Options:"
    puts ""
    puts "  --skip-table: Only add to the new/edit form and show view."
    puts ""
    exit
  end

  # We pass this value to parents to create a new Scaffolding::Transformer because
  # we don't actually need knowledge of the parent to add the new field.
  parents = [""]
  child = argv[0]

  # get all the attributes.
  attributes = argv[1..]

  check_required_options_for_attributes("crud-field", attributes, child)

  transformer = Scaffolding::Transformer.new(child, parents, @options)
  transformer.add_attributes_to_various_views(attributes, type: :crud_field)

  transformer.additional_steps.uniq.each_with_index do |additional_step, index|
    color, message = additional_step
    puts ""
    puts "#{index + 1}. #{message}".send(color)
  end
  puts ""
end