blumquist 0.2.0 → 0.3.0

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: be0386ec7a441132a1b6c5f6a230341218c357bc
4
- data.tar.gz: d744092db33a8cd3f753645f99599f428291b5ee
3
+ metadata.gz: fc1879163c3a69fbfd3790e9be1e3a702429efa0
4
+ data.tar.gz: 9ba85c4383afcc83343cfe46d3cc6489605ba9fd
5
5
  SHA512:
6
- metadata.gz: eab80f79b5a23c652f00291243bb79db5b9f4b5454d5f32fd6b8344f97ea52003e0c2d9a97171f54d29418d5e7a1b6815db838eb0be31cce8d3547d73c8fb135
7
- data.tar.gz: 0f346735db4c91f040a1ec6f39e245000293404a643b6ec7153be20353d73ba3b39a8a16e64a9d9bff99b8dcb7883b66de1167e7da63b997312453e3b34e7b32
6
+ metadata.gz: a612a42a7947923848e9b78e06131e02c59b70bfa9021926a12c1b14a3d417a0b65d04a4ae2062f7a7509fd8881a0e3b9e71c47e8b94e98eb850ccd1a5f9cee5
7
+ data.tar.gz: d403bda45208090896a0c5d489b3c4b9567aaea22ac67edc4761226e0c3174a696b7eac29b1cf951cea73f2a37372f3147d970d73969ecb82ef5a382144eb11b
@@ -1,3 +1,8 @@
1
+ # 0.3.0
2
+ - important whitespace changes
3
+ - proper exceptions
4
+ - disallow arrays with undefined item types
5
+
1
6
  # 0.2.0 (Oct-30-15)
2
7
  - validate objects (if desired)
3
8
  - use keyword arguments (in <2.0 compat mode)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Blumquist [![Circle CI](https://circleci.com/gh/moviepilot/blumquist/tree/master.svg?style=svg)](https://circleci.com/gh/moviepilot/blumquist/tree/master) [![Coverage Status](https://coveralls.io/repos/moviepilot/blumquist/badge.svg?branch=master&service=github)](https://coveralls.io/github/moviepilot/blumquist?branch=master)
1
+ # Blumquist [![Circle CI](https://circleci.com/gh/moviepilot/blumquist/tree/master.svg?style=shield)](https://circleci.com/gh/moviepilot/blumquist/tree/master) [![Coverage Status](https://coveralls.io/repos/moviepilot/blumquist/badge.svg?branch=master&service=github)](https://coveralls.io/github/moviepilot/blumquist?branch=master) [![Gem Version](https://badge.fury.io/rb/blumquist.svg)](https://badge.fury.io/rb/blumquist)
2
2
 
3
3
  ![](https://dl.dropboxusercontent.com/u/1953503/blumquist.jpg)
4
4
 
@@ -2,6 +2,7 @@ require "blumquist/version"
2
2
  require 'active_support/core_ext/hash/indifferent_access'
3
3
  require 'json'
4
4
  require 'json-schema'
5
+ require 'blumquist/errors'
5
6
 
6
7
  class Blumquist
7
8
  def initialize(options)
@@ -17,7 +18,7 @@ class Blumquist
17
18
  define_getters
18
19
  end
19
20
 
20
- private
21
+ private
21
22
 
22
23
  def validate_data
23
24
  return unless @validate
@@ -25,15 +26,14 @@ class Blumquist
25
26
  end
26
27
 
27
28
  def validate_schema
28
- if @schema[:type] != 'object'
29
- raise "Can only deal with 'object' types, not '#{@schema[:type]}'"
30
- end
29
+ return if @schema[:type] == 'object'
30
+ raise(Errors::UnsupportedType, @schema[:type])
31
31
  end
32
32
 
33
33
  def resolve_json_pointers
34
34
  @schema[:properties].each do |property, type_def|
35
35
  next unless type_def[:$ref]
36
- resolve_json_pointer!(type_def)
36
+ resolve_json_pointer!(type_def)
37
37
  end
38
38
  end
39
39
 
@@ -43,7 +43,7 @@ class Blumquist
43
43
  key = pointer.split('/').last
44
44
  definition = @schema[:definitions][key]
45
45
 
46
- raise "Can't resolve pointer #{pointer}" unless definition
46
+ raise(Errors::InvalidPointer, pointer) unless definition
47
47
 
48
48
  type_def.merge! definition
49
49
  end
@@ -68,7 +68,7 @@ class Blumquist
68
68
 
69
69
  # We don't know what to do, so let's panic
70
70
  else
71
- raise "Can't handle type '#{type_def}' yet, I'm sorry"
71
+ raise(Errors::UnsupportedType, type_def[:type])
72
72
  end
73
73
 
74
74
  # And define the getter
@@ -77,7 +77,7 @@ class Blumquist
77
77
  end
78
78
 
79
79
  def define_getter(property)
80
- self.class.class_eval do
80
+ self.class.class_eval do
81
81
  define_method(property) do
82
82
  @data[property]
83
83
  end
@@ -93,6 +93,7 @@ class Blumquist
93
93
 
94
94
  def blumquistify_array(property)
95
95
  item_schema = resolve_json_pointer!(@schema[:properties][property][:items])
96
+ raise(Errors::MissingArrayItemsType, @schema[:properties][property]) unless item_schema
96
97
  sub_schema = item_schema.merge(
97
98
  definitions: @schema[:definitions]
98
99
  )
@@ -0,0 +1 @@
1
+ require 'blumquist/errors/unsupported_type'
@@ -0,0 +1,9 @@
1
+ class Blumquist
2
+ module Errors
3
+ class InvalidPointer < RuntimeError
4
+ def initialize(pointer)
5
+ super("Could not find pointer #{pointer.to_s.to_json}")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class Blumquist
2
+ module Errors
3
+ class MissingArrayItemstype < RuntimeError
4
+ def initialize(property)
5
+ super("Array items' type missing in #{property.to_json}")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class Blumquist
2
+ module Errors
3
+ class UnsupportedType < RuntimeError
4
+ def initialize(type)
5
+ super("Only null, boolean, number, string, array and object types are supported. Unsupported type #{type.to_s.to_json}")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  class Blumquist
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jannis Hermanns
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-30 00:00:00.000000000 Z
11
+ date: 2015-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -168,6 +168,10 @@ files:
168
168
  - Rakefile
169
169
  - blumquist.gemspec
170
170
  - lib/blumquist.rb
171
+ - lib/blumquist/errors.rb
172
+ - lib/blumquist/errors/invalid_pointer.rb
173
+ - lib/blumquist/errors/missing_array_items_type.rb
174
+ - lib/blumquist/errors/unsupported_type.rb
171
175
  - lib/blumquist/version.rb
172
176
  homepage: https://github.com/moviepilot/blumquist
173
177
  licenses: