Class: RR::Syncers::OneWaySyncer
- Inherits:
-
Object
- Object
- RR::Syncers::OneWaySyncer
- Defined in:
- lib/rubyrep/syncers/syncers.rb
Overview
This syncer implements a one way sync. Syncer options relevant for this syncer:
* +:direction+: Sync direction. Possible values:
* +:left+
* +:right+
* +:delete+: Default: false. If true, deletes in the target database all
records _not_ existing in the source database.
* +:update+: If true (default), update records in the target database
if different.
* +:insert+: If true (default), copy over records not existing in the
target database.
Instance Attribute Summary collapse
-
#source ⇒ Object
ID of source database (either :left or :right).
-
#source_record_index ⇒ Object
Array index to source row in case #sync_difference
type
is :conflict. -
#sync_helper ⇒ Object
The current SyncHelper object.
-
#target ⇒ Object
ID of target database (either :left or :right).
Class Method Summary collapse
-
.default_options ⇒ Object
Provides default option for the syncer.
Instance Method Summary collapse
-
#initialize(sync_helper) ⇒ OneWaySyncer
constructor
Initializes the syncer * sync_helper: The SyncHelper object provided information and utility functions.
-
#sync_difference(type, row) ⇒ Object
Called to sync the provided difference.
Constructor Details
#initialize(sync_helper) ⇒ OneWaySyncer
Initializes the syncer
* sync_helper: The SyncHelper object provided information and utility
functions.
84 85 86 87 88 89 |
# File 'lib/rubyrep/syncers/syncers.rb', line 84 def initialize(sync_helper) self.sync_helper = sync_helper self.source = sync_helper.[:direction] == :left ? :right : :left self.target = sync_helper.[:direction] == :left ? :left : :right self.source_record_index = sync_helper.[:direction] == :left ? 1 : 0 end |
Instance Attribute Details
#source ⇒ Object
ID of source database (either :left or :right)
63 64 65 |
# File 'lib/rubyrep/syncers/syncers.rb', line 63 def source @source end |
#source_record_index ⇒ Object
Array index to source row in case #sync_difference type
is :conflict. (As in that case the row
parameter is an array of left and right records.)
70 71 72 |
# File 'lib/rubyrep/syncers/syncers.rb', line 70 def source_record_index @source_record_index end |
#sync_helper ⇒ Object
The current SyncHelper object
60 61 62 |
# File 'lib/rubyrep/syncers/syncers.rb', line 60 def sync_helper @sync_helper end |
#target ⇒ Object
ID of target database (either :left or :right)
66 67 68 |
# File 'lib/rubyrep/syncers/syncers.rb', line 66 def target @target end |
Class Method Details
.default_options ⇒ Object
Provides default option for the syncer. Optional. Returns a hash with :key => value pairs.
74 75 76 77 78 79 |
# File 'lib/rubyrep/syncers/syncers.rb', line 74 def self. { :direction => :right, :delete => false, :update => true, :insert => true } end |
Instance Method Details
#sync_difference(type, row) ⇒ Object
Called to sync the provided difference. See DirectTableScan#run for a description of the type
and row
parameters.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rubyrep/syncers/syncers.rb', line 93 def sync_difference(type, row) case type when source if sync_helper.[:insert] sync_helper.insert_record target, sync_helper.tables[target], row end when target if sync_helper.[:delete] sync_helper.delete_record target, sync_helper.tables[target], row end when :conflict if sync_helper.[:update] sync_helper.update_record target, sync_helper.tables[target], row[source_record_index] end end end |