Module: Arproxy

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

Defined Under Namespace

Modules: Plugin Classes: Base, ChainTail, Config, Error, ProxyChain

Constant Summary collapse

VERSION =
'0.2.2'

Class Method Summary collapse

Class Method Details

.clear_configurationObject



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

def clear_configuration
  @config = Config.new
end

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

Yields:

  • (@config)


16
17
18
19
# File 'lib/arproxy.rb', line 16

def configure
  clear_configuration unless @config
  yield @config
end

.disable!Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/arproxy.rb', line 40

def disable!
  unless enable?
    Arproxy.logger.warn "Arproxy is not enabled yet"
    return
  end

  if @proxy_chain
    @proxy_chain.disable!
    @proxy_chain = nil
  end
  @enabled = false
end

.enable!Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/arproxy.rb', line 21

def enable!
  if enable?
    Arproxy.logger.warn "Arproxy has been already enabled"
    return
  end

  unless @config
    raise Arproxy::Error, "Arproxy should be configured"
  end

  # for lazy loading
  ::ActiveRecord::Base

  @proxy_chain = ProxyChain.new @config
  @proxy_chain.enable!

  @enabled = true
end

.enable?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/arproxy.rb', line 53

def enable?
  !!@enabled
end

.loggerObject



65
66
67
68
69
70
71
# File 'lib/arproxy.rb', line 65

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

.proxy_chainObject



73
74
75
# File 'lib/arproxy.rb', line 73

def proxy_chain
  @proxy_chain
end

.reenable!Object



57
58
59
60
61
62
63
# File 'lib/arproxy.rb', line 57

def reenable!
  if enable?
    @proxy_chain.reenable!
  else
    enable!
  end
end