Class: Ethel::Migration

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

Instance Method Summary collapse

Constructor Details

#initialize(source, target) ⇒ Migration

Returns a new instance of Migration.



3
4
5
6
7
# File 'lib/ethel/migration.rb', line 3

def initialize(source, target)
  @source = source
  @target = target
  @operations = []
end

Instance Method Details

#cast(field, type) ⇒ Object



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

def cast(field, type)
  @operations << Operations::Cast.new(field, type)
end

#copy(field) ⇒ Object



9
10
11
# File 'lib/ethel/migration.rb', line 9

def copy(field)
  @operations << Operations::Copy.new(field)
end

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ethel/migration.rb', line 17

def run
  @operations.each do |operation|
    operation.before_transform(@source, @target)
  end
  @target.prepare

  @source.each do |row|
    row = @operations.inject(row) { |r, op| op.transform(r) }
    @target.add_row(row)
  end
  @target.flush
end