Class: HTTPAdapter::Connection
- Inherits:
-
Object
- Object
- HTTPAdapter::Connection
- Defined in:
- lib/httpadapter/connection.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(host, port, connection, options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #join ⇒ Object
- #open ⇒ Object
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, ={}) 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 = end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
71 72 73 |
# File 'lib/httpadapter/connection.rb', line 71 def connection @connection end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
71 72 73 |
# File 'lib/httpadapter/connection.rb', line 71 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
71 72 73 |
# File 'lib/httpadapter/connection.rb', line 71 def port @port end |
Instance Method Details
#close ⇒ Object
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 |
#join ⇒ Object
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 |
#open ⇒ Object
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 |