Class: RailsExtend::MigrationsGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- RailsExtend::MigrationsGenerator
- Includes:
- ActiveRecord::Generators::Migration
- Defined in:
- lib/generators/rails_extend/migrations_generator.rb
Instance Attribute Summary collapse
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Instance Method Summary collapse
Instance Attribute Details
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
8 9 10 |
# File 'lib/generators/rails_extend/migrations_generator.rb', line 8 def tables @tables end |
Instance Method Details
#create_migration_file ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/generators/rails_extend/migrations_generator.rb', line 10 def create_migration_file file_name = "extend_migration_#{file_index}" RailsExtend::Models.db_tables_hash.each do |mig_paths, tables| next if tables.blank? @tables = tables path = Array(mig_paths)[0] migration_template 'migration.rb', File.join(path, "#{file_name}.rb") end end |
#file_index ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/generators/rails_extend/migrations_generator.rb', line 21 def file_index ups = ActiveRecord::Base.connection.migration_context.migrations_status.select do |status, version, name| status == 'up' && name.start_with?('Extend migration ') end if ups.present? index = ups[-1][-1].delete_prefix 'Extend migration ' index.to_i + 1 else 1 end end |