Class: Ethel::Migration
- Inherits:
-
Object
- Object
- Ethel::Migration
- Defined in:
- lib/ethel/migration.rb
Instance Method Summary collapse
- #cast(field, type) ⇒ Object
- #copy(field) ⇒ Object
-
#initialize(source, target) ⇒ Migration
constructor
A new instance of Migration.
- #run ⇒ Object
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 |
#run ⇒ Object
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 |