strong_json 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/lib/strong_json/types.rb +4 -0
- data/lib/strong_json/version.rb +1 -1
- data/spec/json_spec.rb +13 -0
- 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: 203acba136e0a5e13955cb71eaf772b437490bf1
|
4
|
+
data.tar.gz: d7e81bffc189686f7d3ea48d5c589456aa30253b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1d96614ae765a7eb3287b51d83dfbdaf07384c2316e32f41bc38f4ff85beadb3248bd751f814fbe27b1049cf329a5c2365894781c1c398d0e606dbf179b3728
|
7
|
+
data.tar.gz: 6fb5d0c5ed6b24c26994268c72d116bb7d70efd932648437bc644259a5828ec0c34ad1077466ffdb274e31e2805947b6638c76e4a75376efa4d823dc18972cce
|
data/README.md
CHANGED
@@ -118,10 +118,11 @@ There are some alias for `optional(base)`, where base is base types, as the foll
|
|
118
118
|
* `literal?(lit)`
|
119
119
|
* `any?`
|
120
120
|
|
121
|
-
|
121
|
+
Shortcuts for complex data are also defined as the following:
|
122
122
|
|
123
|
-
* `array?(ty)`
|
124
|
-
* `object?(fields)`
|
123
|
+
* `optional(array(ty))` → `array?(ty)`
|
124
|
+
* `optional(object(fields))` → `object?(fields)`
|
125
|
+
* `optional(enum(types))` → `enum?(types)`
|
125
126
|
|
126
127
|
## Contributing
|
127
128
|
|
data/lib/strong_json/types.rb
CHANGED
data/lib/strong_json/version.rb
CHANGED
data/spec/json_spec.rb
CHANGED
@@ -9,4 +9,17 @@ describe "StrongJSON.new" do
|
|
9
9
|
|
10
10
|
expect(s.checkout.coerce(items: [ { name: "test", count: 1, price: "2.33", comment: "dummy" }], type: 1)).to eq(items: [ { name: "test", count: 1, price: "2.33" }], type: 1)
|
11
11
|
end
|
12
|
+
|
13
|
+
it "tests enums" do
|
14
|
+
s = StrongJSON.new do
|
15
|
+
let :enum, object(e1: enum(string, number), e2: enum?(literal(1), literal(2)))
|
16
|
+
end
|
17
|
+
|
18
|
+
expect(s.enum.coerce(e1: "")).to eq(e1: "")
|
19
|
+
expect(s.enum.coerce(e1: 0)).to eq(e1: 0)
|
20
|
+
expect(s.enum.coerce(e1: 0, e2: 1)).to eq(e1: 0, e2: 1)
|
21
|
+
expect(s.enum.coerce(e1: 0, e2: 2)).to eq(e1: 0, e2: 2)
|
22
|
+
expect{ s.enum.coerce(e1: false) }.to raise_error(StrongJSON::Type::Error)
|
23
|
+
expect{ s.enum.coerce(e1: "", e2: 3) }.to raise_error(StrongJSON::Type::Error)
|
24
|
+
end
|
12
25
|
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
|
+
version: 0.7.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: 2018-
|
11
|
+
date: 2018-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|