Sha256: 42aaa1776e0a70dead8fe5ac913f7161899d2918a43efa12cecffa536edd42f3

Contents?: true

Size: 859 Bytes

Versions: 1

Compression:

Stored size: 859 Bytes

Contents

module MigrationTools
  module MigrationExtension

    attr_accessor :migration_group

    def group(arg = nil)
      unless MigrationTools::MIGRATION_GROUPS.member?(arg.to_s)
        raise "Invalid group \"#{arg.to_s}\" - valid groups are #{MigrationTools::MIGRATION_GROUPS.inspect}"
      end

      self.migration_group = arg.to_s
    end

    def migrate_with_forced_groups(direction)
      if MigrationTools.forced? && migration_group.blank?
        raise "Cowardly refusing to run migration without group. Ner ner ner ner ner, shame shame shame."
      end
      migrate_without_forced_groups(direction)
    end
  end
end

ActiveRecord::Migration.class_eval do
  extend MigrationTools::MigrationExtension
  class << self
    alias_method_chain :migrate, :forced_groups
  end
end
ActiveRecord::MigrationProxy.delegate :migration_group, :to => :migration

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
migration_tools-0.1.5 lib/migration_tools/migration_extension.rb