Class: Arproxy::ProxyChain

Inherits:
Object
  • Object
show all
Defined in:
lib/arproxy/proxy_chain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ProxyChain

Returns a new instance of ProxyChain.



8
9
10
11
# File 'lib/arproxy/proxy_chain.rb', line 8

def initialize(config)
  @config = config
  setup
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



6
7
8
# File 'lib/arproxy/proxy_chain.rb', line 6

def connection
  @connection
end

#headObject (readonly)

Returns the value of attribute head.



5
6
7
# File 'lib/arproxy/proxy_chain.rb', line 5

def head
  @head
end

#tailObject (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

#disable!Object



43
44
45
46
47
48
# File 'lib/arproxy/proxy_chain.rb', line 43

def disable!
  @config.adapter_class.class_eval do
    alias_method :execute, :execute_without_arproxy
    ::Arproxy.logger.debug("Arproxy: Disabled")
  end
end

#enable!Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/arproxy/proxy_chain.rb', line 31

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



25
26
27
28
29
# File 'lib/arproxy/proxy_chain.rb', line 25

def reenable!
  disable!
  setup
  enable!
end