Sha256: 695aee188ceae0603fdb0e3e44850ee5b0d715ee762f61170146235228409bf5

Contents?: true

Size: 1.19 KB

Versions: 17

Compression:

Stored size: 1.19 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 template_path, 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 template_path
        DataMigrate.config.data_template_path
      end

      def migration_base_class_name
        "ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]"
      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

17 entries across 17 versions & 1 rubygems

Version Path
data_migrate-9.1.3 lib/generators/data_migration/data_migration_generator.rb
data_migrate-9.1.2 lib/generators/data_migration/data_migration_generator.rb
data_migrate-11.0.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-11.0.0.rc3 lib/generators/data_migration/data_migration_generator.rb
data_migrate-11.0.0.rc lib/generators/data_migration/data_migration_generator.rb
data_migrate-9.4.4 lib/generators/data_migration/data_migration_generator.rb
data_migrate-9.4.2 lib/generators/data_migration/data_migration_generator.rb
data_migrate-9.4.1 lib/generators/data_migration/data_migration_generator.rb
data_migrate-9.4.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-9.3.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-9.2.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-9.1.1 lib/generators/data_migration/data_migration_generator.rb
data_migrate-9.1.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-10.0.3.rc lib/generators/data_migration/data_migration_generator.rb
data_migrate-10.0.0.rc1 lib/generators/data_migration/data_migration_generator.rb
data_migrate-9.0.0 lib/generators/data_migration/data_migration_generator.rb
data_migrate-8.5.0 lib/generators/data_migration/data_migration_generator.rb