Module: FreshConnection::Extend::ArRelation
- Defined in:
- lib/fresh_connection/extend/ar_relation.rb
Instance Method Summary collapse
- #calculate(*args) ⇒ Object
- #enable_replica_access ⇒ Object
- #enable_slave_access ⇒ Object
- #exists?(*args) ⇒ Boolean
- #manage_access(replica_access = enable_replica_access, &block) ⇒ Object
- #pluck(*args) ⇒ Object
- #read_master ⇒ Object
- #read_master! ⇒ Object
- #read_master_value ⇒ Object
- #read_master_value=(value) ⇒ Object
Instance Method Details
#calculate(*args) ⇒ Object
27 28 29 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 27 def calculate(*args) manage_access { super } end |
#enable_replica_access ⇒ Object
57 58 59 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 57 def enable_replica_access connection.open_transactions == 0 && !read_master_value end |
#enable_slave_access ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 61 def enable_slave_access ActiveSupport::Deprecation.warn( "'enable_slave_access' is deprecated and will removed from version 2.4.0. use 'enable_replica_access' insted." ) enable_replica_access end |
#exists?(*args) ⇒ Boolean
31 32 33 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 31 def exists?(*args) manage_access { super } end |
#manage_access(replica_access = enable_replica_access, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 9 def manage_access(replica_access = enable_replica_access, &block) if @klass.master_db_only? FreshConnection::AccessControl.force_master_access(&block) else retry_count = 0 begin FreshConnection::AccessControl.access(replica_access, &block) rescue *FreshConnection::AccessControl.catch_exceptions if @klass.replica_connection_recovery? retry_count += 1 retry if retry_count < RETRY_LIMIT end raise end end end |
#pluck(*args) ⇒ Object
35 36 37 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 35 def pluck(*args) manage_access { super } end |
#read_master ⇒ Object
39 40 41 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 39 def read_master spawn.read_master! end |
#read_master! ⇒ Object
43 44 45 46 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 43 def read_master! self.read_master_value = true self end |
#read_master_value ⇒ Object
48 49 50 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 48 def read_master_value @values[:read_master] end |
#read_master_value=(value) ⇒ Object
52 53 54 55 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 52 def read_master_value=(value) raise ImmutableRelation if @loaded @values[:read_master] = value end |