Module: RailsAssist::Migration
- Includes:
- Rails::Generators::Migration, FileNameHelper
- Defined in:
- lib/migration_assist/class_methods.rb,
lib/migration_assist/namespaces.rb,
lib/migration_assist/implementation.rb,
lib/migration_assist/helper/file_name.rb
Overview
NOTE: Alternative to use this helper is to inherit from ActiveRecord::Generators::Base which provides the #next_migration_number class method that lets #migration_template work as expected
Defined Under Namespace
Modules: ClassMethods, FileNameHelper
Class Attribute Summary collapse
-
.orm ⇒ Object
Returns the value of attribute orm.
-
.rails_root_dir ⇒ Object
Returns the value of attribute rails_root_dir.
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #latest_migration_file(dir, name) ⇒ Object
- #migration(name, template_name = nil) ⇒ Object
-
#next_migration_number(dirname) ⇒ Object
:nodoc:.
- #reverse_class_names!(migration_path) ⇒ Object
- #reverse_migration!(migration_path) ⇒ Object
- #reverse_migration_name(name) ⇒ Object
- #reverse_up_down_methods!(migration_path) ⇒ Object
Methods included from FileNameHelper
#artifact_path, #db_dir, #existing_file_name, #find_migration, #make_file_name, #migration_dir, #migration_file_name, #root_dir, #type_postfix
Class Attribute Details
.orm ⇒ Object
Returns the value of attribute orm.
8 9 10 |
# File 'lib/migration_assist/class_methods.rb', line 8 def orm @orm end |
.rails_root_dir ⇒ Object
Returns the value of attribute rails_root_dir.
7 8 9 |
# File 'lib/migration_assist/class_methods.rb', line 7 def rails_root_dir @rails_root_dir end |
Class Method Details
.included(base) ⇒ Object
:nodoc:
11 12 13 |
# File 'lib/migration_assist/class_methods.rb', line 11 def self.included(base) #:nodoc: base.extend ClassMethods end |
Instance Method Details
#latest_migration_file(dir, name) ⇒ Object
31 32 33 |
# File 'lib/migration_assist/implementation.rb', line 31 def latest_migration_file dir, name self.class.latest_migration_file dir, name end |
#migration(name, template_name = nil) ⇒ Object
35 36 37 |
# File 'lib/migration_assist/implementation.rb', line 35 def migration name, template_name=nil migration_template("#{template_name || name}.erb", migration_file_name(name)) end |
#next_migration_number(dirname) ⇒ Object
:nodoc:
15 16 17 18 19 20 21 |
# File 'lib/migration_assist/class_methods.rb', line 15 def next_migration_number(dirname) #:nodoc: orm = RailsAssist::Migration.orm || Rails.configuration.generators.[:rails][:orm] require "rails/generators/#{orm}" "#{orm.to_s.camelize}::Generators::Base".constantize.next_migration_number(dirname) rescue raise NotImplementedError end |
#reverse_class_names!(migration_path) ⇒ Object
18 19 20 21 22 |
# File 'lib/migration_assist/implementation.rb', line 18 def reverse_class_names! migration_path # Change class name gsub_file migration_path, /class Add/, 'class Remove' gsub_file migration_path, /class Create/, 'class Drop' end |
#reverse_migration!(migration_path) ⇒ Object
13 14 15 16 |
# File 'lib/migration_assist/implementation.rb', line 13 def reverse_migration! migration_path reverse_class_names! migration_path reverse_up_down_methods! migration_path end |
#reverse_migration_name(name) ⇒ Object
9 10 11 |
# File 'lib/migration_assist/implementation.rb', line 9 def reverse_migration_name name name.gsub(/^add_/, 'remove_').gsub(/^create_/, 'drop_') end |
#reverse_up_down_methods!(migration_path) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/migration_assist/implementation.rb', line 24 def reverse_up_down_methods! migration_path # swap up and down methods gsub_file migration_path, /up/, 'dwn' gsub_file migration_path, /down/, 'up' gsub_file migration_path, /dwn/, 'down' end |