Skip to content

Commit

Permalink
Add schema and metadata information to the definition file
Browse files Browse the repository at this point in the history
Since the definition file is often used in third party applications, I
need a way to reference changes to the schema itself directly in the
file.

I adopted the approach where the will be always a _ element in the file
containing metadata, such as the schema version.

Consumers should always check if (and compare the version) before
processing the definition list.
  • Loading branch information
weppos committed Nov 6, 2016
1 parent 0ffaa35 commit ef826e8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .simplecov
@@ -1,3 +1,4 @@
SimpleCov.start do
add_filter "/spec/"
end
add_filter "/utils/"
end
1 change: 1 addition & 0 deletions lib/whois/server.rb
Expand Up @@ -61,6 +61,7 @@ def self.load_definitions
def self.load_json(file)
type = File.basename(file, File.extname(file)).to_sym
JSON.load(File.read(file)).each do |allocation, settings|
next if allocation == "_"
define(type, allocation, settings.delete("host"), Hash[settings.map { |k,v| [k.to_sym, v] }])
end
end
Expand Down
19 changes: 19 additions & 0 deletions utils/deftld.rb
Expand Up @@ -5,6 +5,14 @@
require 'json'

class TldDefs

KEY_SCHEMA = "_".freeze

# The current schema version for the definition file
#
# @return [String] version
SCHEMA_VERSION = "2".freeze

class TldDef
attr_accessor :name

Expand Down Expand Up @@ -86,6 +94,7 @@ def read
end

def write(data)
data[KEY_SCHEMA] = schema_attributes
data = Hash[data.sort_by { |tld, _| tld.split(".").reverse.join(".") }]
JSON.pretty_generate(data)
end
Expand Down Expand Up @@ -128,6 +137,16 @@ def validate
TldDef.new(tld, data)
end; nil
end

private

def schema_attributes
{
"schema" => SCHEMA_VERSION,
"updated" => Time.now.utc,
}
end

end

args = ARGV
Expand Down

0 comments on commit ef826e8

Please sign in to comment.