Sha256: dd4146b93dab45a5d5b00273eec628229e5477c1d77fe47cc56452291d77283c

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

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

module OldSql
  class InstallMigrationsGenerator < 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
      sleep 1 # ensure scripts have different timestamps
      migration_template 'add_old_sql_admin_to_users_migration.rb', "db/migrate/add_old_sql_admin_to_#{model_name}.rb" rescue p $!.message
      gsub_file "db/migrate/#{@migration_number}_add_old_sql_admin_to_#{model_name}.rb", /devise_model/, "#{model_name}"
      gsub_file "db/migrate/#{@migration_number}_add_old_sql_admin_to_#{model_name}.rb", /DeviseModel/, "#{model_name.capitalize}"
      #sleep 1 # ensure scripts have different timestamps
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
old_sql-1.49.0 lib/generators/old_sql/install_migrations_generator.rb
old_sql-1.48.0 lib/generators/old_sql/install_migrations_generator.rb
old_sql-1.47.0 lib/generators/old_sql/install_migrations_generator.rb