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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2c0790e62786b58b745937e719400b92650cefc
4
- data.tar.gz: 5ebd25f60ea10ab9daa1cf7e85463dcc46d0e0ba
3
+ metadata.gz: f84d2a4e6b928cf36942d379b3ab5b6150ff81a9
4
+ data.tar.gz: df2f57544abd446f73c4dffdd6b1790215d93ed3
5
5
  SHA512:
6
- metadata.gz: 90570084208102b04cb5f8278f1c39775ed56f310b456fbb6e2811b5289452afb8f9b38593ec96f7f1fb92de4111d1bae047985ef80e159621267549c387b3bc
7
- data.tar.gz: 54f672eace3b69cabdb67232988690e04a4012b2ab146ddd6cb5455b269bc12068d0fc29a6e98d7ec2fcde1d778038fb5fc672fdfdf8bae87e6c003fb31a3399
6
+ metadata.gz: b21c80d08cd1d633467fa384549be02170229c2dd8e66271db3636d51db0829f7daf957e4edfa14330a528cb776cbc007ab9b484db32d00f811628f7caa277a7
7
+ data.tar.gz: a9ebe5d7ed5fa53852f38f202c686cca5ee6ebc68b436615685006165406e591506b1c44226dffab634c6062b7083960d93331c323575c5d3054343b4ea03bb2
@@ -26,7 +26,9 @@ class Blumquist
26
26
 
27
27
  def validate_data
28
28
  return unless @validate
29
- JSON::Validator.validate!(@schema, @data)
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
@@ -5,3 +5,4 @@ require 'blumquist/errors/invalid_pointer'
5
5
  require 'blumquist/errors/missing_array_items_type'
6
6
  require 'blumquist/errors/missing_properties'
7
7
  require 'blumquist/errors/no_compatible_one_of'
8
+ require 'blumquist/errors/validation'
@@ -0,0 +1,9 @@
1
+ class Blumquist
2
+ module Errors
3
+ class ValidationError < Blumquist::Error
4
+ def initialize(errors)
5
+ super(errors.to_json)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class Blumquist
2
+ module Errors
3
+ class ValidationError < Blumquist::Error
4
+ def initialize(json_schema_gem_exception, schema, data)
5
+ super("#{json_schema_gem_exception} for #{data.to_json}")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  class Blumquist
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
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.5.0
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-02-15 00:00:00.000000000 Z
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.4.8
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