Class: RR::ReplicationDifference
- Inherits:
-
Object
- Object
- RR::ReplicationDifference
- Defined in:
- lib/rubyrep/replication_difference.rb
Overview
Describes a (record specific) difference between both databases as identifed via change log.
Constant Summary collapse
- OTHER_SIDE =
Shortcut to calculate the “other” database.
{ :left => :right, :right => :left }
- DIFF_TYPES =
Resulting diff type based on types of left changes (outer hash) and right changes (inner hash)
{ :insert => {:insert => :conflict, :update => :conflict, :delete => :conflict, :no_change => :left}, :update => {:insert => :conflict, :update => :conflict, :delete => :conflict, :no_change => :left}, :delete => {:insert => :conflict, :update => :conflict, :delete => :no_change, :no_change => :left}, :no_change => {:insert => :right, :update => :right, :delete => :right, :no_change => :no_change} }
Instance Attribute Summary collapse
-
#loaded ⇒ Object
writeonly
Should be set to
true
if this ReplicationDifference instance was successfully loaded. -
#loaders ⇒ Object
The current LoggedChangeLoaders instance.
-
#second_chance ⇒ Object
(also: #second_chance?)
Is set to
true
if first replication attempt failed but it should be tried again later. -
#type ⇒ Object
The type of the difference.
Instance Method Summary collapse
-
#amend ⇒ Object
Amends a difference according to new entries in the change log table.
-
#changes ⇒ Object
A hash with keys :
left
and / or :right
. -
#initialize(loaders) ⇒ ReplicationDifference
constructor
Creates a new ReplicationDifference instance.
-
#load ⇒ Object
Loads a difference.
-
#loaded? ⇒ Boolean
Returns
true
if a replication difference was loaded. -
#session ⇒ Object
The current Session.
-
#to_yaml_properties ⇒ Object
Prevents session and change loaders from going into YAML output.
Constructor Details
#initialize(loaders) ⇒ ReplicationDifference
Creates a new ReplicationDifference instance. loaders
is teh current LoggedChangeLoaders instance
34 35 36 |
# File 'lib/rubyrep/replication_difference.rb', line 34 def initialize(loaders) self.loaders = loaders end |
Instance Attribute Details
#loaded=(value) ⇒ Object (writeonly)
Should be set to true
if this ReplicationDifference instance was successfully loaded.
40 41 42 |
# File 'lib/rubyrep/replication_difference.rb', line 40 def loaded=(value) @loaded = value end |
#loaders ⇒ Object
The current LoggedChangeLoaders instance
13 14 15 |
# File 'lib/rubyrep/replication_difference.rb', line 13 def loaders @loaders end |
#second_chance ⇒ Object Also known as: second_chance?
Is set to true
if first replication attempt failed but it should be tried again later
23 24 25 |
# File 'lib/rubyrep/replication_difference.rb', line 23 def second_chance @second_chance end |
#type ⇒ Object
The type of the difference. Either
-
:
left
: change in left database -
:
right
: change in right database -
:
conflict
: change in both databases -
:
no_diff
: changes in both databases constitute no difference
20 21 22 |
# File 'lib/rubyrep/replication_difference.rb', line 20 def type @type end |
Instance Method Details
#amend ⇒ Object
Amends a difference according to new entries in the change log table
63 64 65 66 67 68 |
# File 'lib/rubyrep/replication_difference.rb', line 63 def amend loaders.update changes[:left].load changes[:right].load self.type = DIFF_TYPES[changes[:left].type][changes[:right].type] end |
#changes ⇒ Object
A hash with keys :left
and / or :right
. Hash values are LoggedChange instances.
28 29 30 |
# File 'lib/rubyrep/replication_difference.rb', line 28 def changes @changes ||= {} end |
#load ⇒ Object
Loads a difference
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rubyrep/replication_difference.rb', line 71 def load change_times = {} [:left, :right].each do |database| changes[database] = LoggedChange.new loaders[database] change_times[database] = loaders[database].oldest_change_time end return if change_times[:left] == nil and change_times[:right] == nil oldest = nil [:left, :right].each do |database| oldest = OTHER_SIDE[database] if change_times[database] == nil end oldest ||= change_times[:left] <= change_times[:right] ? :left : :right changes[oldest].load_oldest changes[OTHER_SIDE[oldest]].load_specified( session.corresponding_table(oldest, changes[oldest].table), changes[oldest].key) self.type = DIFF_TYPES[changes[:left].type][changes[:right].type] self.loaded = true end |
#loaded? ⇒ Boolean
Returns true
if a replication difference was loaded
43 44 45 |
# File 'lib/rubyrep/replication_difference.rb', line 43 def loaded? @loaded end |
#session ⇒ Object
The current Session.
8 9 10 |
# File 'lib/rubyrep/replication_difference.rb', line 8 def session @session ||= loaders.session end |
#to_yaml_properties ⇒ Object
Prevents session and change loaders from going into YAML output
95 96 97 |
# File 'lib/rubyrep/replication_difference.rb', line 95 def to_yaml_properties instance_variables.sort.reject {|var_name| [:'@session', :'@loaders'].include? var_name} end |