class K8sInternalLb::Address
Attributes
hostname[R]
ip[R]
Public Class Methods
new(hostname: nil, ip: nil, fqdn: nil)
click to toggle source
# 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
Public Instance Methods
==(other)
click to toggle source
Equality overriding
# 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)
click to toggle source
# File lib/k8s_internal_lb/address.rb, line 60 def eql?(other) self == other end
hash()
click to toggle source
# File lib/k8s_internal_lb/address.rb, line 56 def hash [hostname, ip].hash end
hostname=(hostname)
click to toggle source
# File lib/k8s_internal_lb/address.rb, line 22 def hostname=(hostname) if hostname.nil? || hostname.empty? @hostname = nil return end hostname = hostname.to_s.downcase raise ArgumentError, 'Hostname is not allowed to be an FQDN' if hostname.include? '.' @hostname = hostname end
ip=(ip)
click to toggle source
# File lib/k8s_internal_lb/address.rb, line 35 def ip=(ip) ip = IPAddr.new(ip.to_s) unless ip.is_a? IPAddr @ip = ip end
to_json(*params)
click to toggle source
JSON encoding
# File lib/k8s_internal_lb/address.rb, line 42 def to_json(*params) { hostname: hostname, ip: ip }.compact.to_json(*params) end