Class: Resort::Generators::MigrationGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Defined in:
lib/generators/active_record/resort_generator.rb

Overview

Rails generator to add a migration for Resort

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object

Implement the required interface for ‘Rails::Generators::Migration`. Taken from `ActiveRecord` code.



13
14
15
16
17
18
19
# File 'lib/generators/active_record/resort_generator.rb', line 13

def self.next_migration_number(dirname)
  if ActiveRecord::Base.timestamped_migrations
    Time.now.utc.strftime("%Y%m%d%H%M%S")
  else
    "%.3d" % (current_migration_number(dirname) + 1)
  end
end

Instance Method Details

#copy_migration_fileObject

Copies a migration file adding resort fields to a given model



25
26
27
# File 'lib/generators/active_record/resort_generator.rb', line 25

def copy_migration_file
  migration_template 'migration.rb', "db/migrate/add_resort_fields_to_#{table_name.pluralize}.rb"
end