class Arproxy::ProxyChain
Attributes
head[R]
tail[R]
Public Class Methods
new(config)
click to toggle source
# File lib/arproxy/proxy_chain.rb, line 7 def initialize(config) @config = config setup end
Public Instance Methods
connection()
click to toggle source
# File lib/arproxy/proxy_chain.rb, line 49 def connection Thread.current[:arproxy_connection] end
connection=(val)
click to toggle source
# File lib/arproxy/proxy_chain.rb, line 53 def connection=(val) Thread.current[:arproxy_connection] = val end
disable!()
click to toggle source
# 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!()
click to toggle source
# 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
execute_with_arproxy(sql, name=nil)
click to toggle source
# File lib/arproxy/proxy_chain.rb, line 32 def execute_with_arproxy(sql, name=nil) ::Arproxy.proxy_chain.connection = self ::Arproxy.proxy_chain.head.execute sql, name end
reenable!()
click to toggle source
# File lib/arproxy/proxy_chain.rb, line 24 def reenable! disable! setup enable! end
Private Instance Methods
setup()
click to toggle source
# File lib/arproxy/proxy_chain.rb, line 12 def setup @tail = ChainTail.new self @head = @config.proxies.reverse.inject(@tail) do |next_proxy, proxy_config| cls, options = proxy_config proxy = cls.new(*options) proxy.proxy_chain = self proxy.next_proxy = next_proxy proxy end end