Sha256: 510e3feede62d515cf4f7a042e67c84917fc695c39c512e60299403afe4ca138
Contents?: true
Size: 1.12 KB
Versions: 5
Compression:
Stored size: 1.12 KB
Contents
require "generators/data_migrate" require "rails/generators" require "rails/generators/active_record/migration" require "rails/generators/migration" 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", "db/data/#{file_name}.rb" 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 end end end
Version data entries
5 entries across 5 versions & 1 rubygems