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

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


8
9
10
11
# File 'lib/master_slave_adapter/adapter.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.



7
8
9
# File 'lib/master_slave_adapter/adapter.rb', line 7

def file
  @file
end

#positionObject (readonly)

Returns the value of attribute position.



7
8
9
# File 'lib/master_slave_adapter/adapter.rb', line 7

def position
  @position
end

Class Method Details

.zeroObject



18
19
20
# File 'lib/master_slave_adapter/adapter.rb', line 18

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

Instance Method Details

#<=>(other) ⇒ Object



12
13
14
# File 'lib/master_slave_adapter/adapter.rb', line 12

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

#to_sObject



15
16
17
# File 'lib/master_slave_adapter/adapter.rb', line 15

def to_s
  "#{@file}@#{@position}"
end