Class: Janus::Context
- Inherits:
-
Object
- Object
- Janus::Context
- Defined in:
- lib/janus-ar/context.rb
Constant Summary collapse
- THREAD_KEY =
:janus_ar_context
Instance Attribute Summary collapse
-
#last_used_connection ⇒ Object
readonly
Returns the value of attribute last_used_connection.
Class Method Summary collapse
- .last_used_connection ⇒ Object
- .release_all ⇒ Object
- .stick_to_primary ⇒ Object
- .use_primary? ⇒ Boolean
- .used_connection(connection) ⇒ Object
Instance Method Summary collapse
-
#initialize(primary: false, expiry: nil) ⇒ Context
constructor
Stores the staged data with an expiration time based on the current time, and clears any expired entries.
- #potential_write ⇒ Object
- #release_all ⇒ Object
- #stick_to_primary ⇒ Object
- #use_primary? ⇒ Boolean
- #used_connection(connection) ⇒ Object
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_connection ⇒ Object (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_connection ⇒ Object
57 58 59 |
# File 'lib/janus-ar/context.rb', line 57 def last_used_connection current.last_used_connection end |
.release_all ⇒ Object
45 46 47 |
# File 'lib/janus-ar/context.rb', line 45 def release_all current.release_all end |
.stick_to_primary ⇒ Object
41 42 43 |
# File 'lib/janus-ar/context.rb', line 41 def stick_to_primary current.stick_to_primary end |
.use_primary? ⇒ 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_write ⇒ Object
20 21 22 |
# File 'lib/janus-ar/context.rb', line 20 def potential_write stick_to_primary end |
#release_all ⇒ Object
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_primary ⇒ Object
16 17 18 |
# File 'lib/janus-ar/context.rb', line 16 def stick_to_primary @primary = true end |
#use_primary? ⇒ 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 |