class RR::Syncers::OneWaySyncer
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.
Attributes
source[RW]
ID of source database (either :left or :right)
source_record_index[RW]
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.)
sync_helper[RW]
The current SyncHelper
object
target[RW]
ID of target database (either :left or :right)
Public Class Methods
default_options()
click to toggle source
Provides default option for the syncer. Optional. Returns a hash with :key => value pairs.
# File lib/rubyrep/syncers/syncers.rb, line 74 def self.default_options { :direction => :right, :delete => false, :update => true, :insert => true } end
new(sync_helper)
click to toggle source
Initializes the syncer
* sync_helper: The SyncHelper object provided information and utility functions.
# File lib/rubyrep/syncers/syncers.rb, line 84 def initialize(sync_helper) self.sync_helper = sync_helper self.source = sync_helper.sync_options[:direction] == :left ? :right : :left self.target = sync_helper.sync_options[:direction] == :left ? :left : :right self.source_record_index = sync_helper.sync_options[:direction] == :left ? 1 : 0 end
Public Instance Methods
sync_difference(type, row)
click to toggle source
Called to sync the provided difference. See DirectTableScan#run
for a description of the type
and row
parameters.
# File lib/rubyrep/syncers/syncers.rb, line 93 def sync_difference(type, row) case type when source if sync_helper.sync_options[:insert] sync_helper.insert_record target, sync_helper.tables[target], row end when target if sync_helper.sync_options[:delete] sync_helper.delete_record target, sync_helper.tables[target], row end when :conflict if sync_helper.sync_options[:update] sync_helper.update_record target, sync_helper.tables[target], row[source_record_index] end end end