Sha256: 245d267dbe3fe1164bc5c8b0207309e9e8380215b3e51a77a16252d877aabb6e

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

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

module DataMigrate
  module Generators
    class DataMigrationGenerator < Rails::Generators::NamedBase
      namespace "data_migration"
      include Rails::Generators::Migration

      argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
      class_option :skip_schema_migration, :desc => 'Dont generate database schema migration file.', :type => :boolean

      def create_data_migration
        set_local_assigns!
        unless  options.skip_schema_migration?
          migration_template "migration.rb", "db/migrate/#{file_name}.rb"
        end
        migration_template "data_migration.rb", "db/data/#{file_name}.rb"
      end

      protected
      attr_reader :migration_action

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

      def set_local_assigns!
        if file_name =~ /^(add|remove)_.*_(?:to|from)_(.*)/
          @migration_action = $1
          @table_name       = $2.pluralize
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
data_migrate-2.2.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-2.1.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-2.0.1 lib/generators/data_migration/data_migration_generator.rb
data_migrate-2.0.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-1.2.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-1.1.1 lib/generators/data_migration/data_migration_generator.rb
data_migrate-1.1.0 lib/generators/data_migration/data_migration_generator.rb