Class: K8sInternalLb::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/k8s_internal_lb/address.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname: nil, ip: nil, fqdn: nil) ⇒ Address

Returns a new instance of Address.

Raises:

  • (ArgumentError)


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

#hostnameObject

Returns the value of attribute hostname.



8
9
10
# File 'lib/k8s_internal_lb/address.rb', line 8

def hostname
  @hostname
end

#ipObject

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

Returns:

  • (Boolean)


60
61
62
# File 'lib/k8s_internal_lb/address.rb', line 60

def eql?(other)
  self == other
end

#hashObject



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