Class: Coopy::DiffApplySql
- Inherits:
-
DiffOutputAction
- Object
- DiffOutput
- DiffOutputAction
- Coopy::DiffApplySql
- Defined in:
- lib/coopy/diff_apply_sql.rb
Overview
for now, assume no schema changes, and a single table
Instance Method Summary collapse
-
#initialize(db, name = nil) ⇒ DiffApplySql
constructor
A new instance of DiffApplySql.
- #row_delete(rc) ⇒ Object
- #row_insert(rc) ⇒ Object
- #row_update(rc) ⇒ Object
Methods inherited from DiffOutputAction
#apply_row, #row_context, #row_skip
Methods inherited from DiffOutput
#apply_row, #begin_diff, #end_diff, #to_string, #want_context
Constructor Details
#initialize(db, name = nil) ⇒ DiffApplySql
Returns a new instance of DiffApplySql.
6 7 8 9 |
# File 'lib/coopy/diff_apply_sql.rb', line 6 def initialize(db, name = nil) @name = name @db = db end |
Instance Method Details
#row_delete(rc) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/coopy/diff_apply_sql.rb', line 18 def row_delete(rc) cols = rc.active_columns @db.delete(@name, cols.map{|c| c[:title]}, cols.map{|c| rc.value_at(c)}) end |
#row_insert(rc) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/coopy/diff_apply_sql.rb', line 11 def row_insert(rc) cols = rc.active_columns @db.insert(@name, cols.map{|c| c[:title]}, cols.map{|c| rc.value_at(c)}) end |
#row_update(rc) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/coopy/diff_apply_sql.rb', line 25 def row_update(rc) cols = rc.active_columns touched_cols = cols.select{|c| !rc.new_value_at(c).nil?} @db.update(@name, touched_cols.map{|c| c[:title]}, touched_cols.map{|c| rc.new_value_at(c)}, cols.map{|c| c[:title]}, cols.map{|c| rc.value_at(c)}) end |