Class: HTTPAdapter::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/httpadapter/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, connection, options = {}) ⇒ Connection

Returns a new instance of Connection.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/httpadapter/connection.rb', line 19

def initialize(host, port, connection, options={})
  if !host.respond_to?(:to_str)
    raise TypeError, "Expected String, got #{host.class}."
  end
  @host = host.to_str
  if port.kind_of?(Symbol) || !port.respond_to?(:to_i)
    raise TypeError, "Expected Integer, got #{port.class}."
  end
  @port = port.to_i
  unless (1..65535) === @port
    raise ArgumentError, "Invalid port number."
  end
  @connection = connection
  @options = options
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



71
72
73
# File 'lib/httpadapter/connection.rb', line 71

def connection
  @connection
end

#hostObject (readonly)

Returns the value of attribute host.



71
72
73
# File 'lib/httpadapter/connection.rb', line 71

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



71
72
73
# File 'lib/httpadapter/connection.rb', line 71

def port
  @port
end

Instance Method Details

#closeObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/httpadapter/connection.rb', line 47

def close
  if @options[:close]
    method, args, block = @options[:close]
    method ||= :close
    args ||= []
    return @connection.send(method, *args, &block)
  else
    # No-op
    return nil
  end
end

#joinObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/httpadapter/connection.rb', line 59

def join
  if @options[:join]
    method, args, block = @options[:join]
    method ||= :join
    args ||= []
    return @connection.send(method, *args, &block)
  else
    # No-op
    return nil
  end
end

#openObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/httpadapter/connection.rb', line 35

def open
  if @options[:open]
    method, args, block = @options[:open]
    method ||= :open
    args ||= []
    return @connection.send(method, *args, &block)
  else
    # No-op
    return nil
  end
end