Sha256: 2bc6cb43e31ebfc5a8faeb101b96ab3b389fca70b1346ac2693908048da372bf

Contents?: true

Size: 974 Bytes

Versions: 2

Compression:

Stored size: 974 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
      if last_migration = Dir[File.join(path, '*.rb')].sort.last
        @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

2 entries across 2 versions & 1 rubygems

Version Path
sufia-models-6.2.0 lib/generators/sufia/models/abstract_migration_generator.rb
sufia-models-6.1.0 lib/generators/sufia/models/abstract_migration_generator.rb