json_schema 0.19.1 → 0.20.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9cb25401a147f54d711af69f8cb57b43bf59c7f8
4
- data.tar.gz: cca00f70f0db5120ded3b7185b040a4ffa587683
2
+ SHA256:
3
+ metadata.gz: e102114f71484ad7ec4468d6433422c08d7e9a02e20bf635fe7c9a891fce1f99
4
+ data.tar.gz: 63012a87275d8ee64e9465a5b7998d7db859990d9da99ee197153061e1a00c91
5
5
  SHA512:
6
- metadata.gz: 04d2fc7fcbea934e479002e4cd8489ac31b9a6914fcd01a58e890cfd9f3240cafa81959f5bf81029ce3286136ff6e1439af743a48b701def0002e23f538c1ee6
7
- data.tar.gz: d5659272dd75e8de991e90d1b21b447bf9262a100a64b3f46c06f437c0707fd412d74457f9d6be6a7bbfa4aea24742aa3cdbec360a0380b087b56641e03f699a
6
+ metadata.gz: 3e7481a34dd6f9c56684b387c200afed357dd30fca5d443a1a55ce3eb2b9b75535feb05c4682763b464b882cc1c0cf1a80255bf344e897b8b1f7892a0019225f
7
+ data.tar.gz: 1175aed4f46aeea66c9d8d65288f6e7a2c9f232bd1f47fdfed342b79259e08975e8b2c795d1fe75e7da563d9d5c171a3ac4b88b6e0045b6c5e965d060bcc28c0
@@ -33,13 +33,16 @@ module JsonSchema
33
33
  # remove the reader already created by attr_accessor
34
34
  remove_method(attr)
35
35
 
36
- need_dup = [Array, Hash, Set].include?(default.class)
36
+ if [Array, Hash, Set].include?(default.class)
37
+ default = default.freeze
38
+ end
39
+
37
40
  define_method(attr) do
38
41
  val = instance_variable_get(ref)
39
42
  if !val.nil?
40
43
  val
41
44
  else
42
- need_dup ? default.class.new : default
45
+ default
43
46
  end
44
47
  end
45
48
  end
@@ -71,7 +71,7 @@ module JsonSchema
71
71
  paths = @schema_paths[uri] ||= {}
72
72
  paths[schema.pointer] = schema
73
73
 
74
- schema_children(schema).each do |subschema|
74
+ schema_children(schema) do |subschema|
75
75
  build_schema_paths(uri, subschema)
76
76
  end
77
77
 
@@ -114,7 +114,7 @@ module JsonSchema
114
114
  # correct all parent references to point back to ref_schema instead of
115
115
  # new_schema
116
116
  if ref_schema.original?
117
- schema_children(ref_schema).each do |schema|
117
+ schema_children(ref_schema) do |schema|
118
118
  schema.parent = ref_schema
119
119
  end
120
120
  end
@@ -219,47 +219,44 @@ module JsonSchema
219
219
  end
220
220
 
221
221
  def schema_children(schema)
222
- Enumerator.new do |yielder|
223
- schema.all_of.each { |s| yielder << s }
224
- schema.any_of.each { |s| yielder << s }
225
- schema.one_of.each { |s| yielder << s }
226
- schema.definitions.each { |_, s| yielder << s }
227
- schema.pattern_properties.each { |_, s| yielder << s }
228
- schema.properties.each { |_, s| yielder << s }
229
-
230
- if additional = schema.additional_properties
231
- if additional.is_a?(Schema)
232
- yielder << additional
233
- end
222
+ schema.all_of.each { |s| yield s }
223
+ schema.any_of.each { |s| yield s }
224
+ schema.one_of.each { |s| yield s }
225
+ schema.definitions.each { |_, s| yield s }
226
+ schema.pattern_properties.each { |_, s| yield s }
227
+ schema.properties.each { |_, s| yield s }
228
+
229
+ if additional = schema.additional_properties
230
+ if additional.is_a?(Schema)
231
+ yield additional
234
232
  end
233
+ end
235
234
 
236
- if schema.not
237
- yielder << schema.not
238
- end
235
+ if schema.not
236
+ yield schema.not
237
+ end
239
238
 
240
- # can either be a single schema (list validation) or multiple (tuple
241
- # validation)
242
- if items = schema.items
243
- if items.is_a?(Array)
244
- items.each { |s| yielder << s }
245
- else
246
- yielder << items
247
- end
239
+ # can either be a single schema (list validation) or multiple (tuple
240
+ # validation)
241
+ if items = schema.items
242
+ if items.is_a?(Array)
243
+ items.each { |s| yield s }
244
+ else
245
+ yield items
248
246
  end
247
+ end
249
248
 
250
- # dependencies can either be simple or "schema"; only replace the
251
- # latter
252
- schema.dependencies.values.
253
- select { |s| s.is_a?(Schema) }.
254
- each { |s| yielder << s }
255
-
256
- # schemas contained inside hyper-schema links objects
257
- if schema.links
258
- schema.links.map { |l| [l.schema, l.target_schema] }.
259
- flatten.
260
- compact.
261
- each { |s| yielder << s }
262
- end
249
+ # dependencies can either be simple or "schema"; only replace the
250
+ # latter
251
+ schema.dependencies.
252
+ each_value { |s| yield s if s.is_a?(Schema) }
253
+
254
+ # schemas contained inside hyper-schema links objects
255
+ if schema.links
256
+ schema.links.each { |l|
257
+ yield l.schema if l.schema
258
+ yield l.target_schema if l.target_schema
259
+ }
263
260
  end
264
261
  end
265
262
 
@@ -267,19 +264,21 @@ module JsonSchema
267
264
  # prevent endless recursion
268
265
  return [] unless schema.original?
269
266
 
270
- schema_children(schema).reduce([]) do |arr, subschema|
267
+ arr = []
268
+ schema_children(schema) do |subschema|
271
269
  if !subschema.expanded?
272
270
  arr += [subschema.reference]
273
271
  else
274
272
  arr += unresolved_refs(subschema)
275
273
  end
276
274
  end
275
+ arr
277
276
  end
278
277
 
279
278
  def traverse_schema(schema)
280
279
  add_reference(schema)
281
280
 
282
- schema_children(schema).each do |subschema|
281
+ schema_children(schema) do |subschema|
283
282
  if subschema.reference && !subschema.expanded?
284
283
  dereference(subschema, [])
285
284
  end
@@ -264,7 +264,7 @@ module JsonSchema
264
264
 
265
265
  def pointer
266
266
  if parent
267
- parent.pointer + "/" + fragment
267
+ (parent.pointer + "/".freeze + fragment).freeze
268
268
  else
269
269
  fragment
270
270
  end
@@ -26,7 +26,15 @@ describe JsonSchema::Attributes do
26
26
 
27
27
  hash = obj.copyable_default_with_object
28
28
  assert_equal({}, hash)
29
- hash[:x] = 123
29
+ ex = if defined?(FrozenError)
30
+ FrozenError
31
+ else
32
+ RuntimeError
33
+ end
34
+
35
+ assert_raises(ex) do
36
+ hash[:x] = 123
37
+ end
30
38
 
31
39
  # This is a check to make sure that the new object is not the same object
32
40
  # as the one that we just mutated above. When assigning defaults the module
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.1
4
+ version: 0.20.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-28 00:00:00.000000000 Z
11
+ date: 2019-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ecma-re-validator
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  version: '0'
169
169
  requirements: []
170
170
  rubyforge_project:
171
- rubygems_version: 2.6.14
171
+ rubygems_version: 2.7.7
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: A JSON Schema V4 and Hyperschema V4 parser and validator.