Module: Proxifier::Proxify

Included in:
TCPSocket
Defined in:
lib/proxifier/env.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



23
24
25
26
27
28
# File 'lib/proxifier/env.rb', line 23

def self.included(klass)
  klass.class_eval do
    alias_method :initialize_without_proxy, :initialize
    alias_method :initialize, :initialize_with_proxy
  end
end

Instance Method Details

#initialize_with_proxy(host, port, options_or_local_host = {}, local_port = nil, options_if_local_host = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/proxifier/env.rb', line 30

def initialize_with_proxy(host, port, options_or_local_host = {}, local_port = nil, options_if_local_host = {})
  if options_or_local_host.is_a?(Hash)
    local_host = nil
    options = options_or_local_host
  else
    local_host = options_or_local_host
    options = options_if_local_host
  end

  if options[:proxy] && (proxy = Proxifier::Proxy(options.delete(:proxy), options)) && proxy.proxify?(host)
    initialize_without_proxy(proxy.host, proxy.port, local_host, local_port)
    begin
      proxy.proxify(self, host, port)
    rescue
      close
      raise
    end
  else
    initialize_without_proxy(host, port, local_host, local_port)
  end
end