Class: ServerRegistryClient::Server
- Inherits:
-
Object
- Object
- ServerRegistryClient::Server
- Defined in:
- lib/server-registry-client/models/server.rb
Instance Attribute Summary collapse
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#id ⇒ Object
Returns the value of attribute id.
-
#ip_address ⇒ Object
Returns the value of attribute ip_address.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(id = nil, hostname = nil, ip_address = nil, port = nil) ⇒ Server
constructor
A new instance of Server.
- #matches?(server) ⇒ Boolean
Constructor Details
#initialize(id = nil, hostname = nil, ip_address = nil, port = nil) ⇒ Server
Returns a new instance of Server.
10 11 12 13 14 15 |
# File 'lib/server-registry-client/models/server.rb', line 10 def initialize(id=nil, hostname=nil, ip_address=nil, port=nil) @id = id @hostname = hostname @ip_address = ip_address @port = port end |
Instance Attribute Details
#hostname ⇒ Object
Returns the value of attribute hostname.
6 7 8 |
# File 'lib/server-registry-client/models/server.rb', line 6 def hostname @hostname end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/server-registry-client/models/server.rb', line 5 def id @id end |
#ip_address ⇒ Object
Returns the value of attribute ip_address.
7 8 9 |
# File 'lib/server-registry-client/models/server.rb', line 7 def ip_address @ip_address end |
#port ⇒ Object
Returns the value of attribute port.
8 9 10 |
# File 'lib/server-registry-client/models/server.rb', line 8 def port @port end |
Instance Method Details
#matches?(server) ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/server-registry-client/models/server.rb', line 17 def matches?(server) result = false we_have_hostname = !self.hostname.blank? we_have_ip_address = !self.ip_address.blank? we_have_port = !self.port.blank? they_have_hostname = !server.hostname.blank? they_have_ip_address = !server.ip_address.blank? they_have_port = !server.port.blank? ip_address_matches = (we_have_ip_address && they_have_ip_address && self.ip_address == server.ip_address) hostname_matches = (we_have_hostname && they_have_hostname && self.hostname == server.hostname) port_matches = if we_have_port && they_have_port && self.port == server.port && (ip_address_matches || hostname_matches) true elsif they_have_port && !we_have_port && (ip_address_matches || hostname_matches) true elsif !they_have_port && !we_have_port && (ip_address_matches || hostname_matches) true elsif we_have_port && they_have_port && self.port == server.port && (!we_have_hostname && they_have_hostname) true else false end if self.id == server.id result = true else if ip_address_matches result = (true && port_matches) elsif hostname_matches result = (true && port_matches) else result = port_matches end end return result end |