Sha256: 2c97c50a85561fcb0d533fe8c629c5eaffb4ce303b927f789b6f5439e4c23c5a

Contents?: true

Size: 1.34 KB

Versions: 18

Compression:

Stored size: 1.34 KB

Contents

require "generators/data_migrate"
require "rails/generators"
require "rails/generators/active_record/migration"
require "rails/generators/migration"
require "data_migrate/config"

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

      argument :attributes, type: :array, default: [], banner: "field:type field:type"

      def create_data_migration
        set_local_assigns!
        migration_template "data_migration.rb", data_migrations_file_path
      end

      protected

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

      def migration_base_class_name
        if ActiveRecord.version >= Gem::Version.new("5.0")
          "ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]"
        elsif ActiveRecord.version >= Gem::Version.new("5.2")
          "DataMigrate::MigrationContext"
        else
          "ActiveRecord::Migration"
        end
      end

      def data_migrations_file_path
        File.join(data_migrations_path, "#{file_name}.rb")
      end

      def data_migrations_path
        DataMigrate.config.data_migrations_path
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
data_migrate-7.0.2 lib/generators/data_migration/data_migration_generator.rb
data_migrate-7.0.1 lib/generators/data_migration/data_migration_generator.rb
data_migrate-7.0.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-6.8.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-6.7.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-6.6.2 lib/generators/data_migration/data_migration_generator.rb
data_migrate-6.6.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-6.5.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-6.4.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-6.3.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-6.2.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-6.1.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-6.0.7 lib/generators/data_migration/data_migration_generator.rb
data_migrate-6.0.6 lib/generators/data_migration/data_migration_generator.rb
data_migrate-6.0.5 lib/generators/data_migration/data_migration_generator.rb
data_migrate-6.0.4.beta lib/generators/data_migration/data_migration_generator.rb
data_migrate-6.0.3.beta lib/generators/data_migration/data_migration_generator.rb
data_migrate-6.0.1.beta lib/generators/data_migration/data_migration_generator.rb