Class: DataMigrations::Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/data_migrations/migration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, options = {}) {|_self| ... } ⇒ Migration

Returns a new instance of Migration.

Yields:

  • (_self)

Yield Parameters:



5
6
7
8
9
10
11
# File 'lib/data_migrations/migration.rb', line 5

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

  yield self
end

Instance Attribute Details

#instructionsObject (readonly)

Returns the value of attribute instructions.



3
4
5
# File 'lib/data_migrations/migration.rb', line 3

def instructions
  @instructions
end

#sourceObject (readonly)

Returns the value of attribute source.



3
4
5
# File 'lib/data_migrations/migration.rb', line 3

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



3
4
5
# File 'lib/data_migrations/migration.rb', line 3

def target
  @target
end

Instance Method Details

#condition(condition = nil) ⇒ Object Also known as: where



17
18
19
# File 'lib/data_migrations/migration.rb', line 17

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

#copy(*args) ⇒ Object



22
23
24
# File 'lib/data_migrations/migration.rb', line 22

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

#exec(*args) ⇒ Object



39
40
41
# File 'lib/data_migrations/migration.rb', line 39

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

#move(*args) ⇒ Object



26
27
28
29
# File 'lib/data_migrations/migration.rb', line 26

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

#remove(*args) ⇒ Object



31
32
33
# File 'lib/data_migrations/migration.rb', line 31

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

#run!Object



13
14
15
# File 'lib/data_migrations/migration.rb', line 13

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

#set(*args) ⇒ Object



35
36
37
# File 'lib/data_migrations/migration.rb', line 35

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