blumquist 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29ba6e431b5d179ef49358e17f117d29a1d05615
4
- data.tar.gz: 7c91510b9be03ebf29b43206e10dc69b4fb43e5d
3
+ metadata.gz: 150c41e7fb3e641e3ce7593c7c9284fd67e8b460
4
+ data.tar.gz: 36068814a20c207c6076832c3e7d30402dcd77b7
5
5
  SHA512:
6
- metadata.gz: 4c8285345e463ee65590ed825b82cd9c4583828191d80d5541521becc48e2bf3f31b1347cc81ecef0d467d1de5daa9c66d61fb844760173b9d00efa7313071ec
7
- data.tar.gz: dd6ac867efcef1d457aa13db890c5d433b28766d68c6d38f1e7ec9924ba0530d89bba7e056f48c3e119f2bbbe37dff6199e54192ee386e7bdc3981970af944d1
6
+ metadata.gz: 35a20db0cf40272b03861a20231d4eec2630493d9bc0c4a1d47248c4b4072826bba2d6e117d98b242b9fa0ed9b6c79d6b0500d442b69e09bdb28250905573d0b
7
+ data.tar.gz: edffb883241b8688c65eb1025fd318119d364eb4f6885c0f342fd5efee4b445fe929a4a2045ae321e440caef734130a72a7534005910a95f4e1e59bd640c970d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
+ # 0.4.3
2
+ - Allow arrays with single-array-types
3
+
1
4
  # 0.4.2
2
- - Allow type arrays with just one element
5
+ - Allow objects with single-array-types
3
6
 
4
7
  # 0.4.1
5
8
  - Fix broken arrays of objects
data/lib/blumquist.rb CHANGED
@@ -54,13 +54,11 @@ class Blumquist
54
54
 
55
55
  def define_getters
56
56
  @schema[:properties].each do |property, type_def|
57
- types = [type_def[:type]].flatten - ["null"]
58
- type = types.first
59
-
60
57
  # The type_def can contain one or more types.
61
- # We only support single types, or one
58
+ # We only support multiple primitive types, or one
62
59
  # normal type and the null type.
63
- raise(Errors::UnsupportedType, type_def[:type]) if types.length > 1
60
+ types = [type_def[:type]].flatten - ["null"]
61
+ type = types.first
64
62
 
65
63
  # Wrap objects recursively
66
64
  if type == 'object' || type_def[:oneOf]
@@ -73,6 +71,8 @@ class Blumquist
73
71
  # Nothing to do for primitive values
74
72
  elsif primitive_type?(type)
75
73
 
74
+ elsif all_primitive_types(types)
75
+
76
76
  # We don't know what to do, so let's panic
77
77
  else
78
78
  raise(Errors::UnsupportedType, type)
@@ -214,6 +214,8 @@ class Blumquist
214
214
  @data[property] = @data[property].map do |item|
215
215
  Blumquist.new(schema: sub_schema, data: item, validate: false)
216
216
  end
217
+
218
+ # The items are objects, defined directly or through oneOf
217
219
  elsif type_def[:type] == 'object' || type_def[:oneOf]
218
220
  sub_schema = type_def.merge(
219
221
  definitions: @schema[:definitions]
@@ -224,11 +226,20 @@ class Blumquist
224
226
  blumquistify_object(schema: sub_schema, data: item)
225
227
  end
226
228
 
229
+ # The items are all of the same primitive type
227
230
  elsif primitive_type?(type_def[:type])
228
231
 
232
+ # The items might all be primitives, that would be OK
233
+ elsif all_primitive_types(type_def[:type])
234
+
229
235
  # We don't know what to do, so let's panic
230
236
  else
231
237
  raise(Errors::UnsupportedType, type_def[:type])
232
238
  end
233
239
  end
234
- end
240
+
241
+ def all_primitive_types(types)
242
+ return false unless types.is_a?(Array)
243
+ types.all? { |t| primitive_type?(t) }
244
+ end
245
+ end
@@ -1,3 +1,3 @@
1
1
  class Blumquist
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blumquist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jannis Hermanns
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-29 00:00:00.000000000 Z
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport