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.9'

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



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/arproxy.rb', line 37

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

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

  @enabled = true
end

.enable?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/arproxy.rb', line 50

def enable?
  !!@enabled
end

.loggerObject



62
63
64
65
66
67
68
# File 'lib/arproxy.rb', line 62

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

.proxy_chainObject



70
71
72
# File 'lib/arproxy.rb', line 70

def proxy_chain
  @proxy_chain
end

.reenable!Object



54
55
56
57
58
59
60
# File 'lib/arproxy.rb', line 54

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