Skip to content

Commit

Permalink
Merge pull request voxpupuli#375 from iainbeeston/update-metaschema-r…
Browse files Browse the repository at this point in the history
…ake-task

Added a rake task to automatically download the latest metaschemas
  • Loading branch information
iainbeeston authored Mar 8, 2017
2 parents 3c00613 + ff08e1a commit d611009
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,50 @@ task :update_common_tests do
end
end

desc "Update meta-schemas to the latest version"
task :update_meta_schemas do
puts "Updating meta-schemas..."

id_mappings = {
'http://json-schema.org/draft/schema#' => 'https://raw.githubusercontent.com/json-schema-org/json-schema-spec/master/schema.json'
}

require 'open-uri'
require 'thwait'

download_threads = Dir['resources/*.json'].map do |path|
schema_id = File.read(path)[/"\$?id"\s*:\s*"(.*?)"/, 1]
schema_uri = id_mappings[schema_id] || schema_id

Thread.new(schema_uri) do |uri|
Thread.current[:uri] = uri

begin
metaschema = URI(uri).read

File.write(path, metaschema)
rescue StandardError
false
end
end
end

ThreadsWait.all_waits(*download_threads) do |t|
if t.value
puts t[:uri]
else
STDERR.puts "Failed to update meta-schema #{t[:uri]}"
end
end
end

Rake::TestTask.new do |t|
t.libs << "."
t.warning = true
t.verbose = true
t.test_files = FileList.new('test/*_test.rb')
end

task update: [:update_common_tests, :update_meta_schemas]

task :default => :test

0 comments on commit d611009

Please sign in to comment.