Module: Arproxy

Defined in:
lib/arproxy.rb,
lib/arproxy/base.rb,
lib/arproxy/error.rb,
lib/arproxy/config.rb,
lib/arproxy/chain_tail.rb,
lib/arproxy/proxy_chain.rb

Defined Under Namespace

Classes: Base, ChainTail, Config, Error, ProxyChain

Class Method Summary collapse

Class Method Details

.configure {|config| ... } ⇒ Object

Yields:

  • (config)


10
11
12
13
14
# File 'lib/arproxy.rb', line 10

def configure
  config = Config.new
  yield config
  @config = config
end

.disable!Object



30
31
32
33
34
35
36
37
# File 'lib/arproxy.rb', line 30

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

.enable!Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/arproxy.rb', line 16

def enable!
  @proxy_chain = ProxyChain.new @config

  @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

.loggerObject



39
40
41
42
43
44
45
# File 'lib/arproxy.rb', line 39

def logger
  @logger ||= begin
                @config && @config.logger ||
                  defined?(::Rails) && ::Rails.logger ||
                  ::Logger.new(STDOUT)
              end
end

.proxy_chainObject



47
48
49
# File 'lib/arproxy.rb', line 47

def proxy_chain
  @proxy_chain
end