Sha256: f74ff09d65260902d39638d8f563ab64d64004650032ec2dc046ceba73fad329

Contents?: true

Size: 861 Bytes

Versions: 1

Compression:

Stored size: 861 Bytes

Contents

module DataMigrations
  class Migration
    attr_reader :source, :target, :instructions

    def initialize(source, options = {})
      @source = Table.new(source)
      @target = Table.new(options[:to])
      @instructions = []

      yield self
    end

    def run!
      instructions.each(&:execute)
    end

    def condition(condition = nil)
      condition ? @condition = condition : @condition
    end
    alias :where :condition

    def copy(*args)
      instructions << Instruction::Copy.new(self, *args)
    end

    def move(*args)
      copy(*args)
      remove(*args)
    end

    def remove(*args)
      instructions << Instruction::Remove.new(self, *args)
    end

    def set(*args)
      instructions << Instruction::Set.new(self, *args)
    end

    def exec(*args)
      instructions << Instruction::Exec.new(self, *args)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
data_migrations-0.0.1 lib/data_migrations/migration.rb