Class: CounterCulture::WithConnection
- Inherits:
-
Object
- Object
- CounterCulture::WithConnection
- Defined in:
- lib/counter_culture/with_connection.rb
Instance Attribute Summary collapse
-
#recipient ⇒ Object
readonly
Returns the value of attribute recipient.
Instance Method Summary collapse
- #call(reading: false) ⇒ Object
-
#initialize(recipient) ⇒ WithConnection
constructor
A new instance of WithConnection.
Constructor Details
#initialize(recipient) ⇒ WithConnection
Returns a new instance of WithConnection.
3 4 5 |
# File 'lib/counter_culture/with_connection.rb', line 3 def initialize(recipient) @recipient = recipient end |
Instance Attribute Details
#recipient ⇒ Object (readonly)
Returns the value of attribute recipient.
7 8 9 |
# File 'lib/counter_culture/with_connection.rb', line 7 def recipient @recipient end |
Instance Method Details
#call(reading: false) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/counter_culture/with_connection.rb', line 9 def call(reading: false) if rails_7_1_or_greater? use_read_replica = CounterCulture.configuration.use_read_replica && reading role = use_read_replica ? :reading : :writing ActiveRecord::Base.connected_to(role: role) do yield_with_connection { |conn| yield conn } end else # For older Rails versions, just use normal connection yield_with_connection { |conn| yield conn } end end |