Class: Vitrage::Generators::PieceGenerator
- Inherits:
-
ActiveRecord::Generators::ModelGenerator
- Object
- ActiveRecord::Generators::ModelGenerator
- Vitrage::Generators::PieceGenerator
- Defined in:
- lib/generators/vitrage/piece_generator.rb
Instance Method Summary collapse
- #class_name ⇒ Object
-
#create_migration_file ⇒ Object
override ActiveRecord::Generators::ModelGenerator method.
-
#create_model_file ⇒ Object
override ActiveRecord::Generators::ModelGenerator method.
- #create_necessary_views ⇒ Object
- #file_name ⇒ Object
- #table_name ⇒ Object
Instance Method Details
#class_name ⇒ Object
12 13 14 15 |
# File 'lib/generators/vitrage/piece_generator.rb', line 12 def class_name clsn = super clsn[0..3] == "Vtrg" ? clsn : "Vtrg#{clsn}" end |
#create_migration_file ⇒ Object
override ActiveRecord::Generators::ModelGenerator method
28 29 30 31 32 |
# File 'lib/generators/vitrage/piece_generator.rb', line 28 def create_migration_file return unless [:migration] && [:parent].nil? attributes.each { |a| a..delete(:index) if a.reference? && !a.has_index? } if [:indexes] == false migration_template "migrations/create_vitrage_piece.rb", "db/migrate/create_#{table_name}.rb" end |
#create_model_file ⇒ Object
override ActiveRecord::Generators::ModelGenerator method
35 36 37 |
# File 'lib/generators/vitrage/piece_generator.rb', line 35 def create_model_file template 'vitrage_piece.rb', File.join('app/models/vitrage_pieces/', class_path, "#{file_name}.rb") end |
#create_necessary_views ⇒ Object
39 40 41 42 |
# File 'lib/generators/vitrage/piece_generator.rb', line 39 def create_necessary_views copy_file 'views/piece_show_generator.html.erb', File.join('app/views/vitrage/', "_#{file_name}.html.erb") copy_file 'views/piece_form_generator.html.erb', File.join('app/views/vitrage/', "_#{file_name}_form.html.erb") end |
#file_name ⇒ Object
17 18 19 20 |
# File 'lib/generators/vitrage/piece_generator.rb', line 17 def file_name flen = super flen[0..4] == "vtrg_" ? flen : "vtrg_#{flen}" end |
#table_name ⇒ Object
22 23 24 25 |
# File 'lib/generators/vitrage/piece_generator.rb', line 22 def table_name tbns = super tbns[0..4] == "vtrg_" ? tbns : "vtrg_#{tbns}" end |