Class: Aikido::Zen::OutboundConnection
- Inherits:
-
Object
- Object
- Aikido::Zen::OutboundConnection
- Defined in:
- lib/aikido/zen/outbound_connection.rb
Overview
Simple data object to identify connections performed to outbound servers.
Instance Attribute Summary collapse
-
#hits ⇒ Integer
readonly
The number of times that this connection was seen by the hosts collector.
-
#host ⇒ String
readonly
The hostname or IP address to which the connection was attempted.
-
#port ⇒ Integer
readonly
The port number to which the connection was attempted.
Class Method Summary collapse
- .from_json(data) ⇒ Object
-
.from_uri(uri) ⇒ Aikido::Zen::OutboundConnection
Convenience factory to create connection descriptions out of URI objects.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #as_json ⇒ Object
- #hash ⇒ Object
- #hit ⇒ Object
-
#initialize(host:, port:) ⇒ OutboundConnection
constructor
A new instance of OutboundConnection.
- #inspect ⇒ Object
Constructor Details
#initialize(host:, port:) ⇒ OutboundConnection
Returns a new instance of OutboundConnection.
32 33 34 35 |
# File 'lib/aikido/zen/outbound_connection.rb', line 32 def initialize(host:, port:) @host = host.downcase @port = port end |
Instance Attribute Details
#hits ⇒ Integer (readonly)
Returns the number of times that this connection was seen by the hosts collector.
30 31 32 |
# File 'lib/aikido/zen/outbound_connection.rb', line 30 def hits @hits end |
#host ⇒ String (readonly)
Returns the hostname or IP address to which the connection was attempted.
23 24 25 |
# File 'lib/aikido/zen/outbound_connection.rb', line 23 def host @host end |
#port ⇒ Integer (readonly)
Returns the port number to which the connection was attempted.
26 27 28 |
# File 'lib/aikido/zen/outbound_connection.rb', line 26 def port @port end |
Class Method Details
.from_json(data) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/aikido/zen/outbound_connection.rb', line 6 def self.from_json(data) new( host: data[:hostname], port: data[:port] ) end |
.from_uri(uri) ⇒ Aikido::Zen::OutboundConnection
Convenience factory to create connection descriptions out of URI objects.
17 18 19 |
# File 'lib/aikido/zen/outbound_connection.rb', line 17 def self.from_uri(uri) new(host: uri.hostname, port: uri.port) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
47 48 49 50 51 |
# File 'lib/aikido/zen/outbound_connection.rb', line 47 def ==(other) other.is_a?(OutboundConnection) && host == other.host && port == other.port end |
#as_json ⇒ Object
43 44 45 |
# File 'lib/aikido/zen/outbound_connection.rb', line 43 def as_json {hostname: host, port: port, hits: hits}.compact end |
#hash ⇒ Object
54 55 56 |
# File 'lib/aikido/zen/outbound_connection.rb', line 54 def hash [host, port].hash end |
#hit ⇒ Object
37 38 39 40 41 |
# File 'lib/aikido/zen/outbound_connection.rb', line 37 def hit # Lazy initialize @hits, so it stays nil until the connection is tracked. @hits ||= 0 @hits += 1 end |
#inspect ⇒ Object
58 59 60 |
# File 'lib/aikido/zen/outbound_connection.rb', line 58 def inspect "#<#{self.class.name} #{host}:#{port}>" end |