Class: FreshConnection::AccessControl
- Inherits:
-
Object
- Object
- FreshConnection::AccessControl
- Defined in:
- lib/fresh_connection/access_control.rb
Class Method Summary collapse
- .access(enable_replica_access, &block) ⇒ Object
- .catch_exceptions ⇒ Object
- .force_master_access(&block) ⇒ Object
- .replica_access? ⇒ Boolean
Class Method Details
.access(enable_replica_access, &block) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/fresh_connection/access_control.rb', line 8 def access(enable_replica_access, &block) if access_db block.call else db = enable_replica_access ? :replica : :master switch_to(db, &block) end end |
.catch_exceptions ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/fresh_connection/access_control.rb', line 21 def catch_exceptions return @catch_exceptions if defined?(@catch_exceptions) @catch_exceptions = [ActiveRecord::StatementInvalid] @catch_exceptions << ::Mysql2::Error if defined?(::Mysql2) @catch_exceptions += [::PG::Error, ::PGError] if defined?(::PG) @catch_exceptions end |
.force_master_access(&block) ⇒ Object
4 5 6 |
# File 'lib/fresh_connection/access_control.rb', line 4 def force_master_access(&block) switch_to(:master, &block) end |
.replica_access? ⇒ Boolean
17 18 19 |
# File 'lib/fresh_connection/access_control.rb', line 17 def replica_access? access_db == :replica end |