Class: MonoVM::Whois::Registry::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/monovm/whois/registry/definition.rb

Overview

Everything known about how to look up one TLD.

A definition is assembled from several sources: the bundled server list supplies the port 43 host and the registry's "available" marker, while the IANA bootstrap supplies the RDAP base URL. #merge is what lets those arrive independently and still end up on one object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tld:, whois_endpoint: nil, rdap_endpoint: nil, available_match: nil, premium_match: nil, available_when_empty: false, comment: nil, sources: []) ⇒ Definition



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/monovm/whois/registry/definition.rb', line 29

def initialize(tld:, whois_endpoint: nil, rdap_endpoint: nil, available_match: nil,
               premium_match: nil, available_when_empty: false, comment: nil,
               sources: [])
  @tld = tld
  @whois_endpoint = whois_endpoint
  @rdap_endpoint = rdap_endpoint
  @available_match = presence(available_match)
  @premium_match = presence(premium_match)
  @available_when_empty = available_when_empty
  @comment = presence(comment)
  @sources = sources.freeze
  freeze
end

Instance Attribute Details

#available_matchObject (readonly)

Returns the value of attribute available_match.



15
16
17
# File 'lib/monovm/whois/registry/definition.rb', line 15

def available_match
  @available_match
end

#commentObject (readonly)

Returns the value of attribute comment.



15
16
17
# File 'lib/monovm/whois/registry/definition.rb', line 15

def comment
  @comment
end

#premium_matchObject (readonly)

Returns the value of attribute premium_match.



15
16
17
# File 'lib/monovm/whois/registry/definition.rb', line 15

def premium_match
  @premium_match
end

#rdap_endpointObject (readonly)

Returns the value of attribute rdap_endpoint.



15
16
17
# File 'lib/monovm/whois/registry/definition.rb', line 15

def rdap_endpoint
  @rdap_endpoint
end

#sourcesObject (readonly)

Returns the value of attribute sources.



15
16
17
# File 'lib/monovm/whois/registry/definition.rb', line 15

def sources
  @sources
end

#tldObject (readonly)

Returns the value of attribute tld.



15
16
17
# File 'lib/monovm/whois/registry/definition.rb', line 15

def tld
  @tld
end

#whois_endpointObject (readonly)

Returns the value of attribute whois_endpoint.



15
16
17
# File 'lib/monovm/whois/registry/definition.rb', line 15

def whois_endpoint
  @whois_endpoint
end

Instance Method Details

#available_when_empty?Boolean



43
44
45
# File 'lib/monovm/whois/registry/definition.rb', line 43

def available_when_empty?
  @available_when_empty
end

#endpoints(prefer: :rdap) ⇒ Array<Endpoint>

Endpoints to try, best first.

RDAP goes first when available: its answer is structured JSON with an explicit object class or an explicit errorCode, so availability is read rather than guessed. Port 43 free text is the fallback.



63
64
65
66
# File 'lib/monovm/whois/registry/definition.rb', line 63

def endpoints(prefer: :rdap)
  ordered = prefer == :whois ? [whois_endpoint, rdap_endpoint] : [rdap_endpoint, whois_endpoint]
  ordered.compact
end

#inspectObject



105
106
107
108
# File 'lib/monovm/whois/registry/definition.rb', line 105

def inspect
  "#<#{self.class.name} #{tld} whois=#{whois_endpoint&.host || "-"} " \
    "rdap=#{rdap_endpoint ? "yes" : "no"}>"
end

#merge(other) ⇒ Definition

Combine with another definition for the same TLD. Values from other win where it has them, so later sources override earlier ones — that is how a user's override file beats the bundled list.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/monovm/whois/registry/definition.rb', line 78

def merge(other)
  return self if other.nil?

  self.class.new(
    tld: tld,
    whois_endpoint: other.whois_endpoint || whois_endpoint,
    rdap_endpoint: other.rdap_endpoint || rdap_endpoint,
    available_match: other.available_match || available_match,
    premium_match: other.premium_match || premium_match,
    available_when_empty: other.available_when_empty? || available_when_empty?,
    comment: other.comment || comment,
    sources: (sources + other.sources).uniq
  )
end

#rdap?Boolean



47
48
49
# File 'lib/monovm/whois/registry/definition.rb', line 47

def rdap?
  !rdap_endpoint.nil?
end

#to_hObject



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/monovm/whois/registry/definition.rb', line 93

def to_h
  {
    tld: tld,
    whois: whois_endpoint&.to_s,
    rdap: rdap_endpoint&.to_s,
    available_match: available_match,
    premium_match: premium_match,
    available_when_empty: available_when_empty?,
    sources: sources
  }.compact
end

#usable?Boolean



68
69
70
# File 'lib/monovm/whois/registry/definition.rb', line 68

def usable?
  rdap? || whois?
end

#whois?Boolean



51
52
53
# File 'lib/monovm/whois/registry/definition.rb', line 51

def whois?
  !whois_endpoint.nil?
end