Class RR::Syncers::TwoWaySyncer
In: lib/rubyrep/syncers/two_way_syncer.rb
Parent: Object

This syncer implements a two way sync. Syncer options relevant for this syncer:

  • :left_record_handling, :right_record_handling: Handling of records only existing only in the named database. Can be any of the following:
    • :ignore: No action.
    • :delete: Delete from the source database.
    • :insert: Insert in the target database. Default Setting
    • Proc object: If a Proc object is given, it is responsible for dealing with the record. Called with the following parameters:
      • sync_helper: The current SyncHelper instance.
      • type: :left or :right to designate source database
      • row: column_name => value hash representing the row
  • :sync_conflict_handling: Handling of conflicting records. Can be any of the following:
    • :ignore: No action. Default Setting
    • :left_wins: Update right database with the field values in the left db.
    • :right_wins: Update left database with the field values in the right db.
    • Proc object: If a Proc object is given, it is responsible for dealing with the record. Called with the following parameters:
      • sync_helper: The current SyncHelper instance.
      • type: always :conflict
      • rows: A two element array of rows (column_name => value hashes). First left, than right record.
  • :logged_sync_events: Specifies which types of syncs are logged. Is either a single value or an array of multiple ones. Default: [:ignored_conflicts] Possible values:
    • :ignored_changes: log ignored (but not synced) non-conflict changes
    • :all_changes: log all non-conflict changes
    • :ignored_conflicts: log ignored (but not synced) conflicts
    • :all_conflicts: log all conflicts

Example of using a Proc object:

  lambda do |sync_helper, type, row|
    # delete records existing only in the left database.
    sync_helper.delete(type, row) if type == :left
  end

Methods

Constants

TYPE_DESCRIPTIONS = { :left => 'left_record', :right => 'right_record', :conflict => 'conflict'   Sync type descriptions that are written into the event log

Attributes

sync_helper  [RW]  The current SyncHelper object

Public Class methods

Provides default option for the syncer. Optional. Returns a hash with key => value pairs.

Initializes the syncer

  • sync_helper: The SyncHelper object provided information and utility functions.

Raises an ArgumentError if any of the option in sync_helper.sync_options is invalid.

Public Instance methods

Logs a sync event into the event log table as per configuration options.

  • type: Refer to DirectTableScan#run for a description
  • action: the sync action that is executed (The :left_record_handling / :right_record_handling or :sync_conflict_handling option)
  • row: Refer to DirectTableScan#run for a description

Called to sync the provided difference. See DirectTableScan#run for a description of the type and row parameters.

Verifies if the given :sync_conflict_handling option is valid. Raises an ArgumentError if option is invalid

Verifies if the given :left_record_handling / :right_record_handling option is valid. Raises an ArgumentError if option is invalid

Verifies if the given :replication_logging option /options is / are valid. Raises an ArgumentError if invalid

[Validate]