Skip to content

Commit

Permalink
Removed uuidtools
Browse files Browse the repository at this point in the history
  • Loading branch information
iainbeeston committed Jun 30, 2016
1 parent 2fc35df commit 2abbc19
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 307 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@ matrix:
gemfile: "gemfiles/Gemfile.multi_json.x"
- rvm: "2.3.1"
gemfile: "gemfiles/Gemfile.yajl-ruby.x"
- rvm: "2.3.1"
gemfile: "gemfiles/Gemfile.uuidtools.x"
allow_failures:
- rvm: "1.8"
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed
- Replaced UUIDs with SHA1 hashes as the cache key for parsed schemas

## [2.6.2] - 2016-05-13

### Fixed
Expand Down
5 changes: 0 additions & 5 deletions gemfiles/Gemfile.uuidtools.x

This file was deleted.

6 changes: 6 additions & 0 deletions lib/json-schema/util/uri.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'addressable/uri'
require 'digest/sha1'

module JSON
module Util
Expand Down Expand Up @@ -54,6 +55,11 @@ def self.file_uri(uri)
Addressable::URI.convert_path(parsed_uri.path)
end

def self.fake_uri(string)
digest = Digest::SHA1.hexdigest(string)
parse(digest)
end

def self.unescape_uri(uri)
Addressable::URI.unescape(uri)
end
Expand Down
285 changes: 0 additions & 285 deletions lib/json-schema/util/uuid.rb

This file was deleted.

18 changes: 3 additions & 15 deletions lib/json-schema/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -508,14 +508,6 @@ def validators_for_names(names)

private

if Gem::Specification::find_all_by_name('uuidtools').any?
require 'uuidtools'
@@fake_uuid_generator = lambda{|s| UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, s).to_s }
else
require 'json-schema/util/uuid'
@@fake_uuid_generator = lambda{|s| JSON::Util::UUID.create_v5(s,JSON::Util::UUID::Nil).to_s }
end

def serialize schema
if defined?(MultiJson)
MultiJson.respond_to?(:dump) ? MultiJson.dump(schema) : MultiJson.encode(schema)
Expand All @@ -524,15 +516,11 @@ def serialize schema
end
end

def fake_uuid schema
@@fake_uuid_generator.call(schema)
end

def initialize_schema(schema)
if schema.is_a?(String)
begin
# Build a fake URI for this
schema_uri = JSON::Util::URI.parse(fake_uuid(schema))
schema_uri = JSON::Util::URI.fake_uri(schema)
schema = JSON::Schema.new(JSON::Validator.parse(schema), schema_uri, @options[:version])
if @options[:list] && @options[:fragment].nil?
schema = schema.to_array_schema
Expand All @@ -554,14 +542,14 @@ def initialize_schema(schema)
schema = self.class.schema_for_uri(schema_uri)
if @options[:list] && @options[:fragment].nil?
schema = schema.to_array_schema
schema.uri = JSON::Util::URI.parse(fake_uuid(serialize(schema.schema)))
schema.uri = JSON::Util::URI.fake_uri(serialize(schema.schema))
Validator.add_schema(schema)
end
schema
end
end
elsif schema.is_a?(Hash)
schema_uri = JSON::Util::URI.parse(fake_uuid(serialize(schema)))
schema_uri = JSON::Util::URI.fake_uri(serialize(schema))
schema = JSON::Schema.stringify(schema)
schema = JSON::Schema.new(schema, schema_uri, @options[:version])
if @options[:list] && @options[:fragment].nil?
Expand Down
11 changes: 11 additions & 0 deletions test/uri_util_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require File.expand_path('../support/test_helper', __FILE__)

class UriUtilTest < Minitest::Test
def test_fake_uri_is_unique
refute_equal JSON::Util::URI.fake_uri('foo'), JSON::Util::URI.fake_uri('bar')
end

def test_fake_uri_is_reproducible
assert_equal JSON::Util::URI.fake_uri('foo'), JSON::Util::URI.fake_uri('foo')
end
end

0 comments on commit 2abbc19

Please sign in to comment.