Class: RailsExtend::RenameModuleGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- RailsExtend::RenameModuleGenerator
- Includes:
- ActiveRecord::Generators::Migration
- Defined in:
- lib/generators/rails_extend/rename_module_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/rename_module_generator.rb', line 8 def tables @tables end |
Instance Method Details
#create_migration_file ⇒ Object
10 11 12 13 14 15 |
# File 'lib/generators/rails_extend/rename_module_generator.rb', line 10 def create_migration_file @tables = RailsExtend::Models.migrate_modules_hash.invert file_name = "extend_rename_module_#{file_index}" migration_template 'rename_module.rb', File.join(db_migrate_path, "#{file_name}.rb") end |
#file_index ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/generators/rails_extend/rename_module_generator.rb', line 17 def file_index ups = ActiveRecord::Base.connection.migration_context.migrations_status.select do |status, version, name| status == 'up' && name.start_with?('Extend rename module ') end if ups.present? index = ups[-1][-1].delete_prefix 'Extend rename module ' index.to_i + 1 else 1 end end |