Class: MonoVM::Whois::Registry::Resolution

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

Overview

A name split into its registrable parts, with the definition that serves it.

Produced by ServerRegistry#resolve. Exists so the split and the definition travel together: knowing that example.co.uk has SLD example is only meaningful alongside the fact that .co.uk is the suffix a registry actually serves.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain:, sld:, tld:, definition:, registrable: nil) ⇒ Resolution

Returns a new instance of Resolution.

Parameters:

  • domain (DomainName)

    the full name as queried

  • sld (String)

    the label immediately left of the suffix, ASCII

  • tld (String)

    the matched suffix, with a leading dot, ASCII — this is the key the definitions and the per-TLD pattern tables are indexed by

  • definition (Definition)

    how to look this suffix up

  • registrable (DomainName, nil) (defaults to: nil)

    the registrable name in its Unicode form. Passed in because only the caller that did the splitting still knows the Unicode labels; rebuilding it from the ASCII sld and tld would lose them, and the registries that insist on Unicode over port 43 would silently be sent Punycode.



25
26
27
28
29
30
31
32
33
34
# File 'lib/monovm/whois/registry/resolution.rb', line 25

def initialize(domain:, sld:, tld:, definition:, registrable: nil)
  @domain = domain
  @sld = sld
  @tld = tld
  @definition = definition
  # Built here, not memoised: the instance is frozen, so a lazy ivar would
  # raise FrozenError on first use.
  @registrable = registrable || DomainName.parse("#{sld}#{tld}")
  freeze
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



13
14
15
# File 'lib/monovm/whois/registry/resolution.rb', line 13

def definition
  @definition
end

#domainObject (readonly)

Returns the value of attribute domain.



13
14
15
# File 'lib/monovm/whois/registry/resolution.rb', line 13

def domain
  @domain
end

#registrableObject (readonly)

The registrable name — the SLD plus its suffix, with any subdomain dropped. A lookup for www.example.co.uk must query example.co.uk, because that is the object the registry holds. In Unicode form; call #query for the wire form.



40
41
42
# File 'lib/monovm/whois/registry/resolution.rb', line 40

def registrable
  @registrable
end

#sldObject (readonly)

Returns the value of attribute sld.



13
14
15
# File 'lib/monovm/whois/registry/resolution.rb', line 13

def sld
  @sld
end

#tldObject (readonly)

Returns the value of attribute tld.



13
14
15
# File 'lib/monovm/whois/registry/resolution.rb', line 13

def tld
  @tld
end

Instance Method Details

#inspectObject



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

def inspect
  "#<#{self.class.name} #{sld}|#{tld}>"
end

#queryObject

The ASCII form to put on the wire.



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

def query
  registrable.ascii
end

#to_hObject



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

def to_h
  { domain: domain.to_s, sld: sld, tld: tld, registrable: registrable.to_s }
end