Module: RequestWithSocketCheck

Defined in:
lib/icuke/core_ext.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
# File 'lib/icuke/core_ext.rb', line 4

def self.included(base)
  base.instance_eval do
    alias_method :request_without_socket_check, :request
    alias_method :request, :request_with_socket_check
  end
end

Instance Method Details

#request_with_socket_check(*args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/icuke/core_ext.rb', line 11

def request_with_socket_check(*args)
  begin
    request_without_socket_check(*args)
  rescue NoMethodError => e
    if e.message =~ /undefined method `closed\?' for nil/
      raise Errno::ECONNREFUSED
    else
      raise e
    end
  end
end