Class: Arproxy::ConnectionAdapterPatch
- Inherits:
-
Object
- Object
- Arproxy::ConnectionAdapterPatch
- Defined in:
- lib/arproxy/connection_adapter_patch.rb
Instance Attribute Summary collapse
-
#adapter_class ⇒ Object
readonly
Returns the value of attribute adapter_class.
Class Method Summary collapse
Instance Method Summary collapse
- #disable! ⇒ Object
- #enable! ⇒ Object
-
#initialize(adapter_class) ⇒ ConnectionAdapterPatch
constructor
A new instance of ConnectionAdapterPatch.
Constructor Details
#initialize(adapter_class) ⇒ ConnectionAdapterPatch
Returns a new instance of ConnectionAdapterPatch.
5 6 7 8 |
# File 'lib/arproxy/connection_adapter_patch.rb', line 5 def initialize(adapter_class) @adapter_class = adapter_class @applied_patches = Set.new end |
Instance Attribute Details
#adapter_class ⇒ Object (readonly)
Returns the value of attribute adapter_class.
3 4 5 |
# File 'lib/arproxy/connection_adapter_patch.rb', line 3 def adapter_class @adapter_class end |
Class Method Details
.register_patches(adapter_name, patches: [], binds_patches: []) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/arproxy/connection_adapter_patch.rb', line 10 def self.register_patches(adapter_name, patches: [], binds_patches: []) @@patches ||= {} @@patches[adapter_name] = { patches: patches, binds_patches: binds_patches } end |
Instance Method Details
#disable! ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/arproxy/connection_adapter_patch.rb', line 58 def disable! @applied_patches.dup.each do |target_method| adapter_class.class_eval do if instance_methods.include?(:"#{target_method}_with_arproxy") alias_method target_method, :"#{target_method}_without_arproxy" remove_method :"#{target_method}_with_arproxy" end end @applied_patches.delete(target_method) end ::Arproxy.logger.debug("Arproxy: Disabled (#{adapter_class::ADAPTER_NAME})") end |
#enable! ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/arproxy/connection_adapter_patch.rb', line 43 def enable! patches = @@patches[adapter_class::ADAPTER_NAME] if patches patches[:patches]&.each do |patch| apply_patch patch end patches[:binds_patches]&.each do |binds_patch| apply_patch_binds binds_patch end else raise Arproxy::Error, "Unexpected connection adapter: patches not registered for #{adapter_class&.name}" end ::Arproxy.logger.debug("Arproxy: Enabled (#{adapter_class::ADAPTER_NAME})") end |