jschema 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jschema/json_reference.rb +1 -1
  3. data/lib/jschema/schema_uri.rb +6 -2
  4. data/lib/jschema/simple_validator.rb +3 -3
  5. data/lib/jschema/string_length_validator.rb +2 -2
  6. data/lib/jschema/validator/dependencies.rb +2 -2
  7. data/lib/jschema/validator/format.rb +7 -3
  8. data/lib/jschema/validator/items.rb +2 -2
  9. data/lib/jschema/validator/max_items.rb +2 -2
  10. data/lib/jschema/validator/max_properties.rb +2 -2
  11. data/lib/jschema/validator/maximum.rb +2 -2
  12. data/lib/jschema/validator/min_items.rb +2 -2
  13. data/lib/jschema/validator/min_properties.rb +2 -2
  14. data/lib/jschema/validator/minimum.rb +2 -2
  15. data/lib/jschema/validator/multiple_of.rb +2 -2
  16. data/lib/jschema/validator/pattern.rb +2 -2
  17. data/lib/jschema/validator/properties.rb +2 -2
  18. data/lib/jschema/validator/required.rb +2 -2
  19. data/lib/jschema/validator/unique_items.rb +2 -2
  20. metadata +4 -78
  21. data/test/assert_received.rb +0 -15
  22. data/test/string_length_validator_tests.rb +0 -18
  23. data/test/test_assert_received.rb +0 -39
  24. data/test/test_integration.rb +0 -30
  25. data/test/test_json_reference.rb +0 -115
  26. data/test/test_schema.rb +0 -132
  27. data/test/test_schema_ref.rb +0 -19
  28. data/test/test_schema_uri.rb +0 -56
  29. data/test/test_validator.rb +0 -29
  30. data/test/validator/argument_is_array_of_schemas_tests.rb +0 -22
  31. data/test/validator/assertions.rb +0 -56
  32. data/test/validator/properties_limit_tests.rb +0 -13
  33. data/test/validator/schema_validation_helpers.rb +0 -29
  34. data/test/validator/test_all_of.rb +0 -30
  35. data/test/validator/test_any_of.rb +0 -31
  36. data/test/validator/test_dependencies.rb +0 -106
  37. data/test/validator/test_enum.rb +0 -30
  38. data/test/validator/test_format.rb +0 -78
  39. data/test/validator/test_items.rb +0 -119
  40. data/test/validator/test_max_items.rb +0 -26
  41. data/test/validator/test_max_length.rb +0 -30
  42. data/test/validator/test_max_properties.rb +0 -29
  43. data/test/validator/test_maximum.rb +0 -58
  44. data/test/validator/test_min_items.rb +0 -27
  45. data/test/validator/test_min_length.rb +0 -30
  46. data/test/validator/test_min_properties.rb +0 -29
  47. data/test/validator/test_minimum.rb +0 -58
  48. data/test/validator/test_multiple_of.rb +0 -38
  49. data/test/validator/test_not.rb +0 -32
  50. data/test/validator/test_one_of.rb +0 -31
  51. data/test/validator/test_pattern.rb +0 -32
  52. data/test/validator/test_properties.rb +0 -128
  53. data/test/validator/test_required.rb +0 -30
  54. data/test/validator/test_simple_validator.rb +0 -107
  55. data/test/validator/test_type.rb +0 -97
  56. data/test/validator/test_unique_items.rb +0 -30
  57. data/test/validator/validation_against_schemas_tests.rb +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d590fc0ec0125af0eddda1de53da9dacae3531ed
4
- data.tar.gz: fac78348f9d9bc7a044b109e1c0402a6b572cf78
3
+ metadata.gz: a5975d1ffb59b9a5adaaaa4155bfa277ee36c18d
4
+ data.tar.gz: b159e075f06114b2beebfdafd78e4e991600bd6b
5
5
  SHA512:
6
- metadata.gz: 3622b6dca13c53afe5454d08fead0af4aebcb3103f86f6d75c9119f79131ea2f6a7704d8f85f9da111adaa3b8d27328383a0663082d844073aaa7497bc4aed10
7
- data.tar.gz: 744703a630e62f1aae528778c01332709fb83ea8383f4fbfe0a6c8346d6d5346a24c47eac6e45130b5a0eec3245a5d153bcc0e14793964ba3d593c3fc7f68c30
6
+ metadata.gz: 5d363449dfdeba0d314bec5da9229c230d5d5b23d52552983218f92e9792c75cda7369fa201b80b5085d2273cf572955742b709d9d5f230bbbf7fe5312df6246
7
+ data.tar.gz: 063973f04bed0d87bd855d5111160817122c701f1465bb838bd0448881ad293aa4114df1b8d0e9767096ba175c8daf465617a6c48daac27310a9acad5d9c53cb
@@ -65,7 +65,7 @@ module JSchema
65
65
  schema_data = JSON.parse download_schema(uri)
66
66
  parent_schema = schema && schema.parent
67
67
  Schema.build(schema_data, parent_schema, uri.to_s)
68
- rescue JSON::ParserError, Timeout::Error
68
+ rescue JSON::ParserError, Timeout::Error, Errno::ECONNREFUSED
69
69
  raise InvalidSchema, "Failed to download external schema: #{uri}"
70
70
  end
71
71
 
@@ -1,3 +1,5 @@
1
+ require 'webrick/httputils'
2
+
1
3
  module JSchema
2
4
  class SchemaURI
3
5
  class << self
@@ -29,8 +31,10 @@ module JSchema
29
31
 
30
32
  def uri(uri_string)
31
33
  # NOTE: We need to escape % because URI class does not allow such
32
- # characters within URI fragment (which is wrong).
33
- URI(URI.escape(uri_string, '%'))
34
+ # characters within URI fragment (which is wrong). Originally I used
35
+ # URI.escape(str, '%'), but this method has become obsolete.
36
+ escaped_uri = WEBrick::HTTPUtils._escape(uri_string, /([%])/)
37
+ URI(escaped_uri)
34
38
  end
35
39
  end
36
40
  end
@@ -6,7 +6,7 @@ module JSchema
6
6
  new(*args, parent) unless args.compact.empty?
7
7
  end
8
8
 
9
- protected
9
+ private
10
10
 
11
11
  attr_accessor :keywords
12
12
  end
@@ -28,7 +28,7 @@ module JSchema
28
28
  end
29
29
 
30
30
  def validate(instance)
31
- if !applicable_types || applicable_types.any? { |type| type === instance }
31
+ if !applicable_type || instance.is_a?(applicable_type)
32
32
  validate_instance(instance)
33
33
  end
34
34
  end
@@ -36,7 +36,7 @@ module JSchema
36
36
  private
37
37
 
38
38
  # Hook method
39
- def applicable_types; end
39
+ def applicable_type; end
40
40
 
41
41
  def invalid_schema(keyword, value)
42
42
  fail InvalidSchema, "Invalid `#{keyword}` value: #{value.inspect}"
@@ -6,8 +6,8 @@ module JSchema
6
6
  @length_limit = length_limit
7
7
  end
8
8
 
9
- def applicable_types
10
- [String]
9
+ def applicable_type
10
+ String
11
11
  end
12
12
 
13
13
  def valid_length_limit?(length_limit, min_length_limit)
@@ -55,8 +55,8 @@ module JSchema
55
55
  end
56
56
  end
57
57
 
58
- def applicable_types
59
- [Hash]
58
+ def applicable_type
59
+ Hash
60
60
  end
61
61
  end
62
62
  end
@@ -1,4 +1,6 @@
1
+ require 'date'
1
2
  require 'ipaddr'
3
+ require 'webrick/httputils'
2
4
 
3
5
  module JSchema
4
6
  module Validator
@@ -28,8 +30,8 @@ module JSchema
28
30
  end
29
31
  end
30
32
 
31
- def applicable_types
32
- [String]
33
+ def applicable_type
34
+ String
33
35
  end
34
36
 
35
37
  def date_time(instance)
@@ -66,7 +68,9 @@ module JSchema
66
68
  end
67
69
 
68
70
  def uri(instance)
69
- URI.parse instance
71
+ # NOTE: Since URI.escape is obsolete I had to use
72
+ # WEBrick::HTTPUtils.escape
73
+ URI.parse WEBrick::HTTPUtils.escape(instance)
70
74
  rescue URI::InvalidURIError
71
75
  false
72
76
  end
@@ -71,8 +71,8 @@ module JSchema
71
71
  end
72
72
  end
73
73
 
74
- def applicable_types
75
- [Array]
74
+ def applicable_type
75
+ Array
76
76
  end
77
77
  end
78
78
  end
@@ -20,8 +20,8 @@ module JSchema
20
20
  end
21
21
  end
22
22
 
23
- def applicable_types
24
- [Array]
23
+ def applicable_type
24
+ Array
25
25
  end
26
26
  end
27
27
  end
@@ -17,8 +17,8 @@ module JSchema
17
17
  @max_properties = max_properties
18
18
  end
19
19
 
20
- def applicable_types
21
- [Hash]
20
+ def applicable_type
21
+ Hash
22
22
  end
23
23
 
24
24
  def validate_instance(instance)
@@ -23,8 +23,8 @@ module JSchema
23
23
  end
24
24
  end
25
25
 
26
- def applicable_types
27
- [Numeric]
26
+ def applicable_type
27
+ Numeric
28
28
  end
29
29
  end
30
30
  end
@@ -20,8 +20,8 @@ module JSchema
20
20
  end
21
21
  end
22
22
 
23
- def applicable_types
24
- [Array]
23
+ def applicable_type
24
+ Array
25
25
  end
26
26
  end
27
27
  end
@@ -17,8 +17,8 @@ module JSchema
17
17
  @min_properties = min_properties
18
18
  end
19
19
 
20
- def applicable_types
21
- [Hash]
20
+ def applicable_type
21
+ Hash
22
22
  end
23
23
 
24
24
  def validate_instance(instance)
@@ -23,8 +23,8 @@ module JSchema
23
23
  end
24
24
  end
25
25
 
26
- def applicable_types
27
- [Numeric]
26
+ def applicable_type
27
+ Numeric
28
28
  end
29
29
  end
30
30
  end
@@ -25,8 +25,8 @@ module JSchema
25
25
  end
26
26
  end
27
27
 
28
- def applicable_types
29
- [Numeric]
28
+ def applicable_type
29
+ Numeric
30
30
  end
31
31
  end
32
32
  end
@@ -28,8 +28,8 @@ module JSchema
28
28
  end
29
29
  end
30
30
 
31
- def applicable_types
32
- [String]
31
+ def applicable_type
32
+ String
33
33
  end
34
34
  end
35
35
  end
@@ -53,8 +53,8 @@ module JSchema
53
53
  @pattern_properties = pattern_properties
54
54
  end
55
55
 
56
- def applicable_types
57
- [Hash]
56
+ def applicable_type
57
+ Hash
58
58
  end
59
59
 
60
60
  def validate_instance(instance)
@@ -13,8 +13,8 @@ module JSchema
13
13
  @required = required
14
14
  end
15
15
 
16
- def applicable_types
17
- [Hash]
16
+ def applicable_type
17
+ Hash
18
18
  end
19
19
 
20
20
  def validate_instance(instance)
@@ -19,8 +19,8 @@ module JSchema
19
19
  end
20
20
  end
21
21
 
22
- def applicable_types
23
- [Array]
22
+ def applicable_type
23
+ Array
24
24
  end
25
25
  end
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jschema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Papkovskiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-07 00:00:00.000000000 Z
11
+ date: 2015-11-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Implementation of JSON Schema Draft 4
14
14
  email: konstantin@papkovskiy.com
@@ -47,43 +47,6 @@ files:
47
47
  - lib/jschema/validator/required.rb
48
48
  - lib/jschema/validator/type.rb
49
49
  - lib/jschema/validator/unique_items.rb
50
- - test/assert_received.rb
51
- - test/string_length_validator_tests.rb
52
- - test/test_assert_received.rb
53
- - test/test_integration.rb
54
- - test/test_json_reference.rb
55
- - test/test_schema.rb
56
- - test/test_schema_ref.rb
57
- - test/test_schema_uri.rb
58
- - test/test_validator.rb
59
- - test/validator/argument_is_array_of_schemas_tests.rb
60
- - test/validator/assertions.rb
61
- - test/validator/properties_limit_tests.rb
62
- - test/validator/schema_validation_helpers.rb
63
- - test/validator/test_all_of.rb
64
- - test/validator/test_any_of.rb
65
- - test/validator/test_dependencies.rb
66
- - test/validator/test_enum.rb
67
- - test/validator/test_format.rb
68
- - test/validator/test_items.rb
69
- - test/validator/test_max_items.rb
70
- - test/validator/test_max_length.rb
71
- - test/validator/test_max_properties.rb
72
- - test/validator/test_maximum.rb
73
- - test/validator/test_min_items.rb
74
- - test/validator/test_min_length.rb
75
- - test/validator/test_min_properties.rb
76
- - test/validator/test_minimum.rb
77
- - test/validator/test_multiple_of.rb
78
- - test/validator/test_not.rb
79
- - test/validator/test_one_of.rb
80
- - test/validator/test_pattern.rb
81
- - test/validator/test_properties.rb
82
- - test/validator/test_required.rb
83
- - test/validator/test_simple_validator.rb
84
- - test/validator/test_type.rb
85
- - test/validator/test_unique_items.rb
86
- - test/validator/validation_against_schemas_tests.rb
87
50
  homepage: http://github.com/Soylent/jschema
88
51
  licenses:
89
52
  - MIT
@@ -104,45 +67,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
67
  version: '0'
105
68
  requirements: []
106
69
  rubyforge_project:
107
- rubygems_version: 2.2.2
70
+ rubygems_version: 2.5.0
108
71
  signing_key:
109
72
  specification_version: 4
110
73
  summary: JSON Schema implementation
111
- test_files:
112
- - test/assert_received.rb
113
- - test/string_length_validator_tests.rb
114
- - test/test_assert_received.rb
115
- - test/test_integration.rb
116
- - test/test_json_reference.rb
117
- - test/test_schema.rb
118
- - test/test_schema_ref.rb
119
- - test/test_schema_uri.rb
120
- - test/test_validator.rb
121
- - test/validator/argument_is_array_of_schemas_tests.rb
122
- - test/validator/assertions.rb
123
- - test/validator/properties_limit_tests.rb
124
- - test/validator/schema_validation_helpers.rb
125
- - test/validator/test_all_of.rb
126
- - test/validator/test_any_of.rb
127
- - test/validator/test_dependencies.rb
128
- - test/validator/test_enum.rb
129
- - test/validator/test_format.rb
130
- - test/validator/test_items.rb
131
- - test/validator/test_max_items.rb
132
- - test/validator/test_max_length.rb
133
- - test/validator/test_max_properties.rb
134
- - test/validator/test_maximum.rb
135
- - test/validator/test_min_items.rb
136
- - test/validator/test_min_length.rb
137
- - test/validator/test_min_properties.rb
138
- - test/validator/test_minimum.rb
139
- - test/validator/test_multiple_of.rb
140
- - test/validator/test_not.rb
141
- - test/validator/test_one_of.rb
142
- - test/validator/test_pattern.rb
143
- - test/validator/test_properties.rb
144
- - test/validator/test_required.rb
145
- - test/validator/test_simple_validator.rb
146
- - test/validator/test_type.rb
147
- - test/validator/test_unique_items.rb
148
- - test/validator/validation_against_schemas_tests.rb
74
+ test_files: []
@@ -1,15 +0,0 @@
1
- module MiniTest
2
- module Assertions
3
- def assert_received(receiver, message, args = [])
4
- mock = MiniTest::Mock.new
5
- mock.expect(message, nil, args)
6
- receiver_stub = ->(*arg) { mock.__send__ message, *arg }
7
-
8
- receiver.stub message, receiver_stub do
9
- yield if block_given?
10
- end
11
-
12
- mock.verify
13
- end
14
- end
15
- end
@@ -1,18 +0,0 @@
1
- module StringLengthValidatorTests
2
- def test_that_argument_can_be_big_integer
3
- validator(2**64)
4
- end
5
-
6
- def test_that_argument_is_integer
7
- assert_raises(JSchema::InvalidSchema) { validator('invalid') }
8
- end
9
-
10
- def test_that_argument_is_not_null
11
- assert_raises(JSchema::InvalidSchema) { validator(nil) }
12
- end
13
-
14
- def test_that_validation_always_passes_for_non_string_instances
15
- assert validator(1).valid?(nil)
16
- assert validator(1).valid?([1, 2])
17
- end
18
- end
@@ -1,39 +0,0 @@
1
- require 'minitest/autorun'
2
- require_relative 'assert_received'
3
-
4
- class TestAssertReceived < Minitest::Test
5
- def test_message_sending_without_params
6
- assert_received(Object, :class) do
7
- Object.class
8
- end
9
- end
10
-
11
- def test_message_sending_with_params
12
- assert_received(String, :==, [Fixnum]) do
13
- String == Fixnum
14
- end
15
- end
16
-
17
- def test_assertion_failure_when_message_is_not_received
18
- assert_raises(MockExpectationError) do
19
- assert_received(String, :class) do
20
- end
21
- end
22
- end
23
-
24
- def test_assertion_failure_when_unexpected_message_is_received
25
- assert_raises(MockExpectationError) do
26
- assert_received(String, :class) do
27
- String.name
28
- end
29
- end
30
- end
31
-
32
- def test_assertion_failure_when_unexpected_params_are_received
33
- assert_raises(MockExpectationError) do
34
- assert_received(String, :==, [Fixnum]) do
35
- String == Bignum
36
- end
37
- end
38
- end
39
- end