Module: Rails::Generators::MigrationHelper
- Includes:
- BasicHelper, Migration
- Included in:
- MigrationGenerator
- Defined in:
- lib/generator_spec/helpers/migration_helper.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #latest_migration_file ⇒ Object
- #migration(options) ⇒ Object
- #reverse_migration!(migration_path) ⇒ Object
Methods included from BasicHelper
Class Method Details
.included(base) ⇒ Object
:nodoc:
36 37 38 |
# File 'lib/generator_spec/helpers/migration_helper.rb', line 36 def self.included(base) #:nodoc: base.extend ClassMethods end |
Instance Method Details
#latest_migration_file ⇒ Object
56 57 58 |
# File 'lib/generator_spec/helpers/migration_helper.rb', line 56 def latest_migration_file self.class.latest_migration_file end |
#migration(options) ⇒ Object
60 61 62 |
# File 'lib/generator_spec/helpers/migration_helper.rb', line 60 def migration() migration_template "create_users.erb", "db/migrations/#{name}" end |
#reverse_migration!(migration_path) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/generator_spec/helpers/migration_helper.rb', line 40 def reverse_migration! migration_path reverse_migration_path = migration_path.gsub /^add_/, 'remove_' reverse_migration_path = migration_path.gsub /^create_/, 'drop_' FileUtils.mv(migration_path, reverse_migration_path) if migration_path != reverse_migration_path file = File.new(reverse_migration_path) # Change class name gsub_file reverse_migration_path, /class Add/, 'class Remove' gsub_file reverse_migration_path, /class Create/, 'class Drop' # swap up and down methods gsub_file reverse_migration_path, /up/, 'dwn' gsub_file reverse_migration_path, /down/, 'up' gsub_file reverse_migration_path, /dwn/, 'down' end |