strong_json 0.4.0 → 0.5.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: 11c5dbfb77d22e1c192653aec8a65425fc89037a
4
- data.tar.gz: 4c0a5335c72ee7dbe8197f88d00bf695d8175255
3
+ metadata.gz: e9d483b7a44d8b5dff5e7fa548376551d458a6e6
4
+ data.tar.gz: c1156e637dfc48a712dcfa2ccf71864f18918535
5
5
  SHA512:
6
- metadata.gz: 6ad64a761127eafdae6dc349a6afa3940525fac50e7e6300ef8ecb1346b3fef065e9c84646b95853398e137a7c4db183a07bd3ea1c1c28abbd2916ef324144fd
7
- data.tar.gz: 937d1ef703bc65838c4d02c357ff5d96ee963f40b1fc22f3f3add66d61b127646df023b8700c504de3630385ac08fe19faa572fdf627fca40a3e300f1447704b
6
+ metadata.gz: 615fc0454b7898ea953a67c92386676d4d599a98569e093ffae4350140d733f69a0da0c79cb5fe0c7bf99ec5ad378a004929adbe942e7784fc2a31ea5dcb9fa1
7
+ data.tar.gz: 3ca93c4ff958334fdd35cf8372c2b1c05a9e8031749df0188a1c612f83b32b15991a5d419038977ecb3269861628a760ca69c1a18ff8f37c62ccee93783174a3
data/README.md CHANGED
@@ -104,7 +104,7 @@ Testing `type` is done first, and it soon determines if the object is `"person"`
104
104
 
105
105
  ### Literals
106
106
 
107
- * `literal(lit)` The value must `=== lit`
107
+ * `literal(lit)` The value must `== lit`
108
108
 
109
109
  ### Shortcuts
110
110
 
@@ -116,6 +116,7 @@ There are some alias for `optional(base)`, where base is base types, as the foll
116
116
  * `numeric?`
117
117
  * `symbol?`
118
118
  * `literal?(lit)`
119
+ * `any?`
119
120
 
120
121
  Shorthands for `optional(array(ty))` and `optional(object(fields))` are also defined as the following:
121
122
 
@@ -204,10 +204,15 @@ class StrongJSON
204
204
  end
205
205
 
206
206
  def coerce(value, path: [])
207
- type = types.find {|ty| ty =~ value }
207
+ result = types.find do |ty|
208
+ begin
209
+ break ty.coerce(value)
210
+ rescue UnexpectedFieldError, IllegalTypeError, Error # rubocop:disable Lint/HandleExceptions
211
+ end
212
+ end
208
213
 
209
- if type
210
- type.coerce(value, path: path)
214
+ if result
215
+ result
211
216
  else
212
217
  raise Error.new(path: path, type: self, value: value)
213
218
  end
@@ -32,6 +32,10 @@ class StrongJSON
32
32
  StrongJSON::Type::Base.new(:any)
33
33
  end
34
34
 
35
+ def any?
36
+ optional(any)
37
+ end
38
+
35
39
  def prohibited
36
40
  StrongJSON::Type::Base.new(:prohibited)
37
41
  end
@@ -1,3 +1,3 @@
1
1
  class StrongJSON
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strong_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-24 00:00:00.000000000 Z
11
+ date: 2017-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler