Class: ActiveRecord::ConnectionAdapters::MasterSlaveAdapter::Clock

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/master_slave_adapter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, position) ⇒ Clock

Returns a new instance of Clock.

Raises:

  • (ArgumentError)


99
100
101
102
# File 'lib/master_slave_adapter.rb', line 99

def initialize(file, position)
  raise ArgumentError, "file and postion may not be nil" if file.nil? || position.nil?
  @file, @position = file, position.to_i
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



97
98
99
# File 'lib/master_slave_adapter.rb', line 97

def file
  @file
end

#positionObject (readonly)

Returns the value of attribute position.



97
98
99
# File 'lib/master_slave_adapter.rb', line 97

def position
  @position
end

Class Method Details

.infinityObject



116
117
118
# File 'lib/master_slave_adapter.rb', line 116

def self.infinity
  @infinity ||= Clock.new('', Float::MAX.to_i)
end

.zeroObject



112
113
114
# File 'lib/master_slave_adapter.rb', line 112

def self.zero
  @zero ||= Clock.new('', 0)
end

Instance Method Details

#<=>(other) ⇒ Object



104
105
106
# File 'lib/master_slave_adapter.rb', line 104

def <=>(other)
  @file == other.file ? @position <=> other.position : @file <=> other.file
end

#to_sObject



108
109
110
# File 'lib/master_slave_adapter.rb', line 108

def to_s
  [ @file, @position ].join('@')
end