blumquist 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/blumquist.rb +18 -1
- data/lib/blumquist/errors.rb +1 -0
- data/lib/blumquist/errors/validation.rb +9 -0
- data/lib/blumquist/errors/validation_error.rb +9 -0
- data/lib/blumquist/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f84d2a4e6b928cf36942d379b3ab5b6150ff81a9
|
4
|
+
data.tar.gz: df2f57544abd446f73c4dffdd6b1790215d93ed3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b21c80d08cd1d633467fa384549be02170229c2dd8e66271db3636d51db0829f7daf957e4edfa14330a528cb776cbc007ab9b484db32d00f811628f7caa277a7
|
7
|
+
data.tar.gz: a9ebe5d7ed5fa53852f38f202c686cca5ee6ebc68b436615685006165406e591506b1c44226dffab634c6062b7083960d93331c323575c5d3054343b4ea03bb2
|
data/lib/blumquist.rb
CHANGED
@@ -26,7 +26,9 @@ class Blumquist
|
|
26
26
|
|
27
27
|
def validate_data
|
28
28
|
return unless @validate
|
29
|
-
JSON::Validator.
|
29
|
+
errors = JSON::Validator.fully_validate(@schema, @data)
|
30
|
+
return true if errors.length == 0
|
31
|
+
raise(Errors::ValidationError, [errors, @schema, @data])
|
30
32
|
end
|
31
33
|
|
32
34
|
def validate_schema
|
@@ -56,6 +58,16 @@ class Blumquist
|
|
56
58
|
%w{null boolean number string}.include? type.to_s
|
57
59
|
end
|
58
60
|
|
61
|
+
def value_is_of_primitive_type?(value, type)
|
62
|
+
case type
|
63
|
+
when 'null' then value.nil?
|
64
|
+
when 'boolean' then value === true or value === false
|
65
|
+
when 'number' then value.is_a?(Numeric)
|
66
|
+
when 'string' then value.is_a?(String)
|
67
|
+
else false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
59
71
|
def define_getters
|
60
72
|
@schema[:properties].each do |property, type_def|
|
61
73
|
# The type_def can contain one or more types.
|
@@ -177,6 +189,11 @@ class Blumquist
|
|
177
189
|
# We found no matching object definition.
|
178
190
|
# If a primitve is part of the `oneOfs,
|
179
191
|
# that's no problem though.
|
192
|
+
#
|
193
|
+
# TODOs this is only ok if data is actually of that primitive type
|
194
|
+
#
|
195
|
+
# Also check https://gist.github.com/jayniz/e8849ea528af6d205698 and
|
196
|
+
# https://github.com/ruby-json-schema/json-schema/issues/319
|
180
197
|
return data if primitive_allowed
|
181
198
|
|
182
199
|
# We didn't find a schema in oneOf that matches our data
|
data/lib/blumquist/errors.rb
CHANGED
data/lib/blumquist/version.rb
CHANGED
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.5.
|
4
|
+
version: 0.5.1
|
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-
|
11
|
+
date: 2016-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -190,6 +190,8 @@ files:
|
|
190
190
|
- lib/blumquist/errors/no_compatible_one_of.rb
|
191
191
|
- lib/blumquist/errors/unsupported_schema.rb
|
192
192
|
- lib/blumquist/errors/unsupported_type.rb
|
193
|
+
- lib/blumquist/errors/validation.rb
|
194
|
+
- lib/blumquist/errors/validation_error.rb
|
193
195
|
- lib/blumquist/version.rb
|
194
196
|
homepage: https://github.com/moviepilot/blumquist
|
195
197
|
licenses:
|
@@ -211,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
213
|
version: '0'
|
212
214
|
requirements: []
|
213
215
|
rubyforge_project:
|
214
|
-
rubygems_version: 2.
|
216
|
+
rubygems_version: 2.5.1
|
215
217
|
signing_key:
|
216
218
|
specification_version: 4
|
217
219
|
summary: Turn some data and a json schema into an immutable object with getters from
|