Class: ScaffoldPlus::Generators::MigrationGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- ScaffoldPlus::Generators::MigrationGenerator
- Defined in:
- lib/generators/scaffold_plus/migration/migration_generator.rb
Instance Method Summary collapse
- #add_migration ⇒ Object
- #prepare_change_column ⇒ Object
- #prepare_change_table ⇒ Object
- #prepare_not_null ⇒ Object
- #prepare_set_default ⇒ Object
- #prepare_the_lines ⇒ Object
Instance Method Details
#add_migration ⇒ Object
65 66 67 68 |
# File 'lib/generators/scaffold_plus/migration/migration_generator.rb', line 65 def add_migration return unless @the_lines.any? migration_template "change_migration.rb", "db/migrate/#{migration_name}.rb" end |
#prepare_change_column ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/generators/scaffold_plus/migration/migration_generator.rb', line 42 def prepare_change_column return unless .change.present? .change.each do |column| column, new_type = column.split(':') @the_lines << " change_column :#{table_name}, :#{column}, :#{new_type}" end end |
#prepare_change_table ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/generators/scaffold_plus/migration/migration_generator.rb', line 25 def prepare_change_table return unless .remove.present? or .rename.present? @the_lines << " change_table :#{table_name} do |t|" if .remove.present? .remove.each do |column| @the_lines << " t.remove :#{column}" end end if .rename.present? .rename.each do |column| old_name, new_name = column.split(':') @the_lines << " t.rename :#{old_name}, :#{new_name}" end end @the_lines << " end" end |
#prepare_not_null ⇒ Object
50 51 52 53 54 55 |
# File 'lib/generators/scaffold_plus/migration/migration_generator.rb', line 50 def prepare_not_null return unless .not_null.present? .not_null.each do |column| @the_lines << " change_column_null :#{table_name}, :#{column}, false" end end |
#prepare_set_default ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/generators/scaffold_plus/migration/migration_generator.rb', line 57 def prepare_set_default return unless .set_default.present? .set_default.each do |column| column, preset = column.split(':') @the_lines << " change_column_default :#{table_name}, :#{column}, #{preset}" end end |
#prepare_the_lines ⇒ Object
21 22 23 |
# File 'lib/generators/scaffold_plus/migration/migration_generator.rb', line 21 def prepare_the_lines @the_lines = [] end |