Class: K8sInternalLb::Address
- Inherits:
-
Object
- Object
- K8sInternalLb::Address
- Defined in:
- lib/k8s_internal_lb/address.rb
Instance Attribute Summary collapse
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#ip ⇒ Object
Returns the value of attribute ip.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Equality overriding.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(hostname: nil, ip: nil, fqdn: nil) ⇒ Address
constructor
A new instance of Address.
-
#to_json(*params) ⇒ Object
JSON encoding.
Constructor Details
#initialize(hostname: nil, ip: nil, fqdn: nil) ⇒ Address
Returns a new instance of Address.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/k8s_internal_lb/address.rb', line 10 def initialize(hostname: nil, ip: nil, fqdn: nil) raise ArgumentError, 'missing keyword: ip' if fqdn.nil? && ip.nil? if fqdn ip ||= Resolv.getaddress fqdn hostname ||= fqdn.split('.').first end self.hostname = hostname self.ip = ip end |
Instance Attribute Details
#hostname ⇒ Object
Returns the value of attribute hostname.
8 9 10 |
# File 'lib/k8s_internal_lb/address.rb', line 8 def hostname @hostname end |
#ip ⇒ Object
Returns the value of attribute ip.
8 9 10 |
# File 'lib/k8s_internal_lb/address.rb', line 8 def ip @ip end |
Instance Method Details
#==(other) ⇒ Object
Equality overriding
50 51 52 53 54 |
# File 'lib/k8s_internal_lb/address.rb', line 50 def ==(other) return unless other.respond_to?(:hostname) && other.respond_to?(:ip) hostname == other.hostname && ip == other.ip end |
#eql?(other) ⇒ Boolean
60 61 62 |
# File 'lib/k8s_internal_lb/address.rb', line 60 def eql?(other) self == other end |
#hash ⇒ Object
56 57 58 |
# File 'lib/k8s_internal_lb/address.rb', line 56 def hash [hostname, ip].hash end |
#to_json(*params) ⇒ Object
JSON encoding
42 43 44 45 46 47 |
# File 'lib/k8s_internal_lb/address.rb', line 42 def to_json(*params) { hostname: hostname, ip: ip }.compact.to_json(*params) end |