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 +4 -4
- data/README.md +2 -1
- data/lib/strong_json/type.rb +8 -3
- data/lib/strong_json/types.rb +4 -0
- data/lib/strong_json/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9d483b7a44d8b5dff5e7fa548376551d458a6e6
|
4
|
+
data.tar.gz: c1156e637dfc48a712dcfa2ccf71864f18918535
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
|
data/lib/strong_json/type.rb
CHANGED
@@ -204,10 +204,15 @@ class StrongJSON
|
|
204
204
|
end
|
205
205
|
|
206
206
|
def coerce(value, path: [])
|
207
|
-
|
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
|
210
|
-
|
214
|
+
if result
|
215
|
+
result
|
211
216
|
else
|
212
217
|
raise Error.new(path: path, type: self, value: value)
|
213
218
|
end
|
data/lib/strong_json/types.rb
CHANGED
data/lib/strong_json/version.rb
CHANGED
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
|
+
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-
|
11
|
+
date: 2017-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|