Class: MonoVM::Whois::Registry::Sources::JsonFile

Inherits:
Base
  • Object
show all
Defined in:
lib/monovm/whois/registry/sources/json_file.rb

Overview

Reads the server-list JSON format: an array of entries, each mapping a comma-separated extensions list to one endpoint.

[
{
  "extensions": ".com,.net",
  "uri": "socket://whois.verisign-grs.com",
  "available": "No match for",
  "premium": "Reserved",
  "rdap": "https://rdap.verisign.com/com/v1/domain/",
  "available_when_empty": false,
  "comment": "why this entry looks like this"
}
]

Both the bundled list and a user override file use this class — they differ only in path and in whether a missing file is fatal.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, optional: false, name: nil) ⇒ JsonFile

Returns a new instance of JsonFile.

Parameters:

  • path (String)
  • optional (Boolean) (defaults to: false)

    when true, a missing or unreadable file yields no definitions instead of raising

  • name (String, nil) (defaults to: nil)

    identifier recorded on each definition



34
35
36
37
38
39
# File 'lib/monovm/whois/registry/sources/json_file.rb', line 34

def initialize(path:, optional: false, name: nil)
  @path = path
  @optional = optional
  @name = name
  super()
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



28
29
30
# File 'lib/monovm/whois/registry/sources/json_file.rb', line 28

def path
  @path
end

Instance Method Details

#loadHash{String => Definition}

Returns:



50
51
52
53
54
55
56
57
58
# File 'lib/monovm/whois/registry/sources/json_file.rb', line 50

def load
  raw = read
  return {} if raw.nil?

  entries = parse(raw)
  entries.each_with_index.with_object({}) do |(entry, index), definitions|
    add_entry(definitions, entry, index)
  end
end

#nameObject



41
42
43
# File 'lib/monovm/whois/registry/sources/json_file.rb', line 41

def name
  @name || (optional? ? "override" : "bundled")
end

#optional?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/monovm/whois/registry/sources/json_file.rb', line 45

def optional?
  @optional
end