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

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/active_record/connection_adapters/master_slave_adapter/clock.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)


8
9
10
11
# File 'lib/active_record/connection_adapters/master_slave_adapter/clock.rb', line 8

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.



6
7
8
# File 'lib/active_record/connection_adapters/master_slave_adapter/clock.rb', line 6

def file
  @file
end

#positionObject (readonly)

Returns the value of attribute position.



6
7
8
# File 'lib/active_record/connection_adapters/master_slave_adapter/clock.rb', line 6

def position
  @position
end

Class Method Details

.infinityObject



29
30
31
# File 'lib/active_record/connection_adapters/master_slave_adapter/clock.rb', line 29

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

.parse(string) ⇒ Object



33
34
35
36
37
# File 'lib/active_record/connection_adapters/master_slave_adapter/clock.rb', line 33

def self.parse(string)
  new(*string.split('@'))
rescue
  nil
end

.zeroObject



25
26
27
# File 'lib/active_record/connection_adapters/master_slave_adapter/clock.rb', line 25

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

Instance Method Details

#<=>(other) ⇒ Object



13
14
15
# File 'lib/active_record/connection_adapters/master_slave_adapter/clock.rb', line 13

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

#infinity?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/active_record/connection_adapters/master_slave_adapter/clock.rb', line 21

def infinity?
  self == self.class.infinity
end

#to_sObject



17
18
19
# File 'lib/active_record/connection_adapters/master_slave_adapter/clock.rb', line 17

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