Module: FreshConnection::Extend::ArBase
- Defined in:
- lib/fresh_connection/extend/ar_base.rb
Instance Method Summary collapse
- #clear_all_replica_connections! ⇒ Object
- #connection ⇒ Object
- #establish_fresh_connection(spec_name = nil) ⇒ Object
- #master_db_only! ⇒ Object
- #master_db_only? ⇒ Boolean
- #read_master ⇒ Object
- #replica_connection ⇒ Object
- #replica_spec_name ⇒ Object
- #with_master(&block) ⇒ Object
Instance Method Details
#clear_all_replica_connections! ⇒ Object
28 29 30 |
# File 'lib/fresh_connection/extend/ar_base.rb', line 28 def clear_all_replica_connections! __replica_handler.clear_all_connections! end |
#connection ⇒ Object
20 21 22 |
# File 'lib/fresh_connection/extend/ar_base.rb', line 20 def connection super.tap {|c| c.model_class = self } end |
#establish_fresh_connection(spec_name = nil) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/fresh_connection/extend/ar_base.rb', line 32 def establish_fresh_connection(spec_name = nil) spec_name = spec_name.to_s spec_name = "replica" if spec_name.empty? @_replica_spec_name = spec_name __replica_handler.refresh_connection(replica_spec_name) end |
#master_db_only! ⇒ Object
40 41 42 |
# File 'lib/fresh_connection/extend/ar_base.rb', line 40 def master_db_only! @_fresh_connection_master_only = true end |
#master_db_only? ⇒ Boolean
44 45 46 47 |
# File 'lib/fresh_connection/extend/ar_base.rb', line 44 def master_db_only? @_fresh_connection_master_only ||= (self != ActiveRecord::Base && superclass.master_db_only?) end |
#read_master ⇒ Object
8 9 10 |
# File 'lib/fresh_connection/extend/ar_base.rb', line 8 def read_master all.read_master end |
#replica_connection ⇒ Object
24 25 26 |
# File 'lib/fresh_connection/extend/ar_base.rb', line 24 def replica_connection __replica_handler.connection(replica_spec_name) end |
#replica_spec_name ⇒ Object
49 50 51 |
# File 'lib/fresh_connection/extend/ar_base.rb', line 49 def replica_spec_name @_replica_spec_name ||= __search_replica_spec_name end |
#with_master(&block) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/fresh_connection/extend/ar_base.rb', line 12 def with_master(&block) FreshConnection::AccessControl.manage_access( model: self, replica_access: false, &block ) end |