Class: Aikido::Zen::OutboundConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/aikido/zen/outbound_connection.rb

Overview

Simple data object to identify connections performed to outbound servers.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, port:) ⇒ OutboundConnection

Returns a new instance of OutboundConnection.



21
22
23
24
# File 'lib/aikido/zen/outbound_connection.rb', line 21

def initialize(host:, port:)
  @host = host
  @port = port
end

Instance Attribute Details

#hostString (readonly)

Returns the hostname or IP address to which the connection was attempted.

Returns:

  • (String)

    the hostname or IP address to which the connection was attempted.



16
17
18
# File 'lib/aikido/zen/outbound_connection.rb', line 16

def host
  @host
end

#portInteger (readonly)

Returns the port number to which the connection was attempted.

Returns:

  • (Integer)

    the port number to which the connection was attempted.



19
20
21
# File 'lib/aikido/zen/outbound_connection.rb', line 19

def port
  @port
end

Class Method Details

.from_uri(uri) ⇒ Aikido::Zen::OutboundConnection

Convenience factory to create connection descriptions out of URI objects.

Parameters:

  • uri (URI)

Returns:



10
11
12
# File 'lib/aikido/zen/outbound_connection.rb', line 10

def self.from_uri(uri)
  new(host: uri.hostname, port: uri.port)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



30
31
32
33
34
# File 'lib/aikido/zen/outbound_connection.rb', line 30

def ==(other)
  other.is_a?(OutboundConnection) &&
    host == other.host &&
    port == other.port
end

#as_jsonObject



26
27
28
# File 'lib/aikido/zen/outbound_connection.rb', line 26

def as_json
  {hostname: host, port: port}
end

#hashObject



37
38
39
# File 'lib/aikido/zen/outbound_connection.rb', line 37

def hash
  [host, port].hash
end

#inspectObject



41
42
43
# File 'lib/aikido/zen/outbound_connection.rb', line 41

def inspect
  "#<#{self.class.name} #{host}:#{port}>"
end