Sha256: 90bcd560b365f643218a003ec698dcd10fccf5ff362c7ccfb29c208f7eaf8463

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

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", /devise_model/, "#{model_name.pluralize}"
      gsub_file "db/migrate/#{@migration_number}_add_devise_to_#{model_name.singularize}.rb", /DeviseModel/, "#{model_name.singularize.capitalize}"
      
      #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.56.0 lib/generators/old_sql/install_devise_migrations_generator.rb