Class: Keepr::MigrationGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/keepr/migration/migration_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/generators/keepr/migration/migration_generator.rb', line 17

def self.next_migration_number(dirname)
  if timestamped_migrations?
    Time.now.utc.strftime('%Y%m%d%H%M%S')
  else
    format('%.3d', (current_migration_number(dirname) + 1))
  end
end

.timestamped_migrations?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/keepr/migration/migration_generator.rb', line 25

def self.timestamped_migrations?
  (
    ActiveRecord::Base.respond_to?(:timestamped_migrations) &&
      ActiveRecord::Base.timestamped_migrations
  ) ||
    (
      ActiveRecord.respond_to?(:timestamped_migrations) &&
        ActiveRecord.timestamped_migrations
    )
end

Instance Method Details

#create_migration_fileObject



13
14
15
# File 'lib/generators/keepr/migration/migration_generator.rb', line 13

def create_migration_file
  migration_template 'migration.rb', 'db/migrate/keepr_migration.rb'
end