Module: FreshConnection::Extend::ArRelation
- Defined in:
- lib/fresh_connection/extend/ar_relation.rb
Instance Method Summary collapse
- #calculate(*args) ⇒ Object
- #enable_slave_access ⇒ Object
- #exists?(*args) ⇒ Boolean
- #manage_access(slave_access = enable_slave_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
25 26 27 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 25 def calculate(*args) manage_access { super } end |
#enable_slave_access ⇒ Object
55 56 57 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 55 def enable_slave_access connection.open_transactions == 0 && !read_master_value end |
#exists?(*args) ⇒ Boolean
29 30 31 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 29 def exists?(*args) manage_access { super } end |
#manage_access(slave_access = enable_slave_access, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 7 def manage_access(slave_access = enable_slave_access, &block) if @klass.master_db_only? FreshConnection::AccessControl.force_master_access(&block) else retry_count = 0 begin FreshConnection::AccessControl.access(slave_access, &block) rescue *FreshConnection::AccessControl.catch_exceptions if @klass.slave_connection_recovery? retry_count += 1 retry if retry_count < RETRY_LIMIT end raise end end end |
#pluck(*args) ⇒ Object
33 34 35 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 33 def pluck(*args) manage_access { super } end |
#read_master ⇒ Object
37 38 39 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 37 def read_master spawn.read_master! end |
#read_master! ⇒ Object
41 42 43 44 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 41 def read_master! self.read_master_value = true self end |
#read_master_value ⇒ Object
46 47 48 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 46 def read_master_value @values[:read_master] end |
#read_master_value=(value) ⇒ Object
50 51 52 53 |
# File 'lib/fresh_connection/extend/ar_relation.rb', line 50 def read_master_value=(value) raise ImmutableRelation if @loaded @values[:read_master] = value end |