Class: ActsAsTaggableSimple::Generators::MigrationGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- ActsAsTaggableSimple::Generators::MigrationGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/acts_as_taggable_simple/migration/migration_generator.rb
Overview
Generates a migration file for migrating two tables into the database for acts_as_taggable_simple to function:
-
tags
-
taggings
Example usage:
rails generate acts_as_taggable_simple:migration
To migrate the data:
rake db:migrate
Class Method Summary collapse
-
.next_migration_number(path) ⇒ Object
Returns the timestamp for the migration.
-
.orm ⇒ Object
Gets the current orm that rails is using.
-
.orm_has_migration? ⇒ Boolean
Returns
true
if the current orm has a migration file. -
.source_root ⇒ Object
The source root for template migration files.
Instance Method Summary collapse
-
#create_migration_file ⇒ Object
Actually generates the migration file.
Class Method Details
.next_migration_number(path) ⇒ Object
Returns the timestamp for the migration
38 39 40 |
# File 'lib/generators/acts_as_taggable_simple/migration/migration_generator.rb', line 38 def self.next_migration_number(path) Time.now.utc.strftime("%Y%m%d%H%M%S") end |
.orm ⇒ Object
Gets the current orm that rails is using.
ActiveRecord is the only orm currently supported.
23 24 25 |
# File 'lib/generators/acts_as_taggable_simple/migration/migration_generator.rb', line 23 def self.orm Rails::Generators.[:rails][:orm] end |
.orm_has_migration? ⇒ Boolean
Returns true
if the current orm has a migration file
33 34 35 |
# File 'lib/generators/acts_as_taggable_simple/migration/migration_generator.rb', line 33 def self.orm_has_migration? [:active_record].include? orm end |
.source_root ⇒ Object
The source root for template migration files
28 29 30 |
# File 'lib/generators/acts_as_taggable_simple/migration/migration_generator.rb', line 28 def self.source_root File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.class.eql?(String))) end |
Instance Method Details
#create_migration_file ⇒ Object
Actually generates the migration file
Only generates the migration if one exists for the current orm. Looks for lib/generators/acts_as_taggable_simple/migration/templates//migration.rb
46 47 48 49 50 |
# File 'lib/generators/acts_as_taggable_simple/migration/migration_generator.rb', line 46 def create_migration_file if self.class.orm_has_migration? migration_template 'migration.rb', 'db/migrate/acts_as_taggable_simple_migration' end end |