Class: Arproxy::ProxyChain
- Inherits:
-
Object
- Object
- Arproxy::ProxyChain
- Defined in:
- lib/arproxy/proxy_chain.rb
Instance Attribute Summary collapse
-
#head ⇒ Object
readonly
Returns the value of attribute head.
-
#tail ⇒ Object
readonly
Returns the value of attribute tail.
Instance Method Summary collapse
- #connection ⇒ Object
- #connection=(val) ⇒ Object
- #disable! ⇒ Object
- #enable! ⇒ Object
-
#initialize(config) ⇒ ProxyChain
constructor
A new instance of ProxyChain.
- #reenable! ⇒ Object
Constructor Details
#initialize(config) ⇒ ProxyChain
Returns a new instance of ProxyChain.
7 8 9 10 |
# File 'lib/arproxy/proxy_chain.rb', line 7 def initialize(config) @config = config setup end |
Instance Attribute Details
#head ⇒ Object (readonly)
Returns the value of attribute head.
5 6 7 |
# File 'lib/arproxy/proxy_chain.rb', line 5 def head @head end |
#tail ⇒ Object (readonly)
Returns the value of attribute tail.
5 6 7 |
# File 'lib/arproxy/proxy_chain.rb', line 5 def tail @tail end |
Instance Method Details
#connection ⇒ Object
49 50 51 |
# File 'lib/arproxy/proxy_chain.rb', line 49 def connection Thread.current[:arproxy_connection] end |
#connection=(val) ⇒ Object
53 54 55 |
# File 'lib/arproxy/proxy_chain.rb', line 53 def connection=(val) Thread.current[:arproxy_connection] = val end |
#disable! ⇒ Object
42 43 44 45 46 47 |
# File 'lib/arproxy/proxy_chain.rb', line 42 def disable! @config.adapter_class.class_eval do alias_method :execute, :execute_without_arproxy ::Arproxy.logger.debug("Arproxy: Disabled") end end |
#enable! ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/arproxy/proxy_chain.rb', line 30 def enable! @config.adapter_class.class_eval do def execute_with_arproxy(sql, name=nil) ::Arproxy.proxy_chain.connection = self ::Arproxy.proxy_chain.head.execute sql, name end alias_method :execute_without_arproxy, :execute alias_method :execute, :execute_with_arproxy ::Arproxy.logger.debug("Arproxy: Enabled") end end |
#reenable! ⇒ Object
24 25 26 27 28 |
# File 'lib/arproxy/proxy_chain.rb', line 24 def reenable! disable! setup enable! end |