Class: Janus::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/janus-ar/context.rb

Constant Summary collapse

THREAD_KEY =
:janus_ar_context

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(primary: false, expiry: nil) ⇒ Context

Stores the staged data with an expiration time based on the current time, and clears any expired entries. Returns true if any changes were made to the current store



10
11
12
13
14
# File 'lib/janus-ar/context.rb', line 10

def initialize(primary: false, expiry: nil)
  @primary = primary
  @expiry = expiry
  @last_used_connection = :primary
end

Instance Attribute Details

#last_used_connectionObject (readonly)

Returns the value of attribute last_used_connection.



38
39
40
# File 'lib/janus-ar/context.rb', line 38

def last_used_connection
  @last_used_connection
end

Class Method Details

.last_used_connectionObject



57
58
59
# File 'lib/janus-ar/context.rb', line 57

def last_used_connection
  current.last_used_connection
end

.release_allObject



45
46
47
# File 'lib/janus-ar/context.rb', line 45

def release_all
  current.release_all
end

.stick_to_primaryObject



41
42
43
# File 'lib/janus-ar/context.rb', line 41

def stick_to_primary
  current.stick_to_primary
end

.use_primary?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/janus-ar/context.rb', line 53

def use_primary?
  current.use_primary?
end

.used_connection(connection) ⇒ Object



49
50
51
# File 'lib/janus-ar/context.rb', line 49

def used_connection(connection)
  current.used_connection(connection)
end

Instance Method Details

#potential_writeObject



20
21
22
# File 'lib/janus-ar/context.rb', line 20

def potential_write
  stick_to_primary
end

#release_allObject



24
25
26
27
28
# File 'lib/janus-ar/context.rb', line 24

def release_all
  @primary = false
  @expiry = nil
  @last_used_connection = nil
end

#stick_to_primaryObject



16
17
18
# File 'lib/janus-ar/context.rb', line 16

def stick_to_primary
  @primary = true
end

#use_primary?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/janus-ar/context.rb', line 30

def use_primary?
  @primary
end

#used_connection(connection) ⇒ Object



34
35
36
# File 'lib/janus-ar/context.rb', line 34

def used_connection(connection)
  @last_used_connection = connection
end