Sha256: ca7eae2e92f9fcd0d7b11009e842d0396e9eb701dffa0dee1fab79eeefdf70e2

Contents?: true

Size: 1005 Bytes

Versions: 3

Compression:

Stored size: 1005 Bytes

Contents

# -*- encoding : utf-8 -*-
require 'rails/generators'
require 'rails/generators/migration'

class Sufia::Models::AbstractMigrationGenerator < Rails::Generators::Base
  include Rails::Generators::Migration

  # Implement the required interface for Rails::Generators::Migration.
  # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
  def self.next_migration_number(path)
    if @prev_migration_nr
      @prev_migration_nr += 1
    else
      last_migration = Dir[File.join(path, '*.rb')].sort.last
      if last_migration
        @prev_migration_nr = last_migration.sub(File.join(path, '/'), '').to_i + 1
      else
        @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
      end
    end
    @prev_migration_nr.to_s
  end

  protected

    def better_migration_template(file)
      migration_template "migrations/#{file}", "db/migrate/#{file}"
    rescue Rails::Generators::Error => e
      say_status("error", e.message, :red)
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sufia-models-6.5.0 lib/generators/sufia/models/abstract_migration_generator.rb
sufia-models-6.4.0 lib/generators/sufia/models/abstract_migration_generator.rb
sufia-models-6.3.0 lib/generators/sufia/models/abstract_migration_generator.rb