Sha256: 94e370a264b07a6803257132e22bb131d20667655c58dca9671d5a1a02d17b1d

Contents?: true

Size: 997 Bytes

Versions: 1

Compression:

Stored size: 997 Bytes

Contents

require 'rails/generators'
require 'rails/generators/migration'

module OldSql
  class InstallDeviseMigrationsGenerator < Rails::Generators::Base
    include Rails::Generators::Migration
    source_root File.expand_path('../templates', __FILE__)
    argument :model_name, :type => :string, :default => 'user'

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

    def create_migration_file
      migration_template 'add_devise_to_users_migration.rb', "db/migrate/add_devise_to_#{model_name}.rb" rescue p $!.message
      gsub_file "db/migrate/#{@migration_number}_add_devise_to_#{model_name}.rb", /device_model/, "#{model_name}"
      
      #sleep 1 # ensure scripts have different timestamps
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
old_sql-1.45.0 lib/generators/old_sql/install_devise_migrations_generator.rb