Class: MonoVM::Whois::Registry::Definition
- Inherits:
-
Object
- Object
- MonoVM::Whois::Registry::Definition
- 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
-
#available_match ⇒ Object
readonly
Returns the value of attribute available_match.
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#premium_match ⇒ Object
readonly
Returns the value of attribute premium_match.
-
#rdap_endpoint ⇒ Object
readonly
Returns the value of attribute rdap_endpoint.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
-
#tld ⇒ Object
readonly
Returns the value of attribute tld.
-
#whois_endpoint ⇒ Object
readonly
Returns the value of attribute whois_endpoint.
Instance Method Summary collapse
- #available_when_empty? ⇒ Boolean
-
#endpoints(prefer: :rdap) ⇒ Array<Endpoint>
Endpoints to try, best first.
-
#initialize(tld:, whois_endpoint: nil, rdap_endpoint: nil, available_match: nil, premium_match: nil, available_when_empty: false, comment: nil, sources: []) ⇒ Definition
constructor
A new instance of Definition.
- #inspect ⇒ Object
-
#merge(other) ⇒ Definition
Combine with another definition for the same TLD.
- #rdap? ⇒ Boolean
- #to_h ⇒ Object
- #usable? ⇒ Boolean
- #whois? ⇒ Boolean
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_match ⇒ Object (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 |
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
15 16 17 |
# File 'lib/monovm/whois/registry/definition.rb', line 15 def comment @comment end |
#premium_match ⇒ Object (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_endpoint ⇒ Object (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 |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
15 16 17 |
# File 'lib/monovm/whois/registry/definition.rb', line 15 def sources @sources end |
#tld ⇒ Object (readonly)
Returns the value of attribute tld.
15 16 17 |
# File 'lib/monovm/whois/registry/definition.rb', line 15 def tld @tld end |
#whois_endpoint ⇒ Object (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 |
#inspect ⇒ Object
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_h ⇒ Object
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 |