Module: EnumGeneratorHelpers::MigrationNumber
- Included in:
- EnumGenerator
- Defined in:
- lib/generators/enum/enum_generator_helpers/migration_number.rb
Overview
Helper methods to figure out the migration number.
Instance Method Summary collapse
-
#next_migration_number(dirname) ⇒ Integer
Returns the next upcoming migration number.
Instance Method Details
#next_migration_number(dirname) ⇒ Integer
Returns the next upcoming migration number. Sadly, Rails has no API for this, so we're reduced to copying from ActiveRecord::Generators::Migration
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/generators/enum/enum_generator_helpers/migration_number.rb', line 10 def next_migration_number(dirname) # Lifted directly from ActiveRecord::Generators::Migration # Unfortunately, no API is provided by Rails at this time. next_migration_number = current_migration_number(dirname) + 1 if (ActiveRecord::Base.respond_to?(:timestamped_migrations) && ActiveRecord::Base.) || (ActiveRecord.respond_to?(:timestamped_migrations) && ActiveRecord.) # Changed in Rails 7.1 [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max else "%.3d" % next_migration_number end end |