strong_json 0.6.0 → 0.7.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: a5ae6973c112d772bdc495d5d50d5148f767bc71
4
- data.tar.gz: 9c08bcd7842863cd40b727bf05007fec4be82f23
3
+ metadata.gz: 203acba136e0a5e13955cb71eaf772b437490bf1
4
+ data.tar.gz: d7e81bffc189686f7d3ea48d5c589456aa30253b
5
5
  SHA512:
6
- metadata.gz: 6da4d4154502cc0bc422b1b5b1ff22c2033972d5cda06cdaeee3241c5d4eaa511151f622a6297e00dbaad632e20591fe67e1b9415cf755bd44ff83f9c77f5cc7
7
- data.tar.gz: 50668c460b0ac655c48b6a93b4fd1e8c631474e1b70ab3c2850a4bf54e0ac92419a618d708e36fe3ab420f0189f3a61bd1e009019a4ccc51703bf989d02c8e63
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
- Shorthands for `optional(array(ty))` and `optional(object(fields))` are also defined as the following:
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
 
@@ -87,5 +87,9 @@ class StrongJSON
87
87
  def literal?(value)
88
88
  optional(literal(value))
89
89
  end
90
+
91
+ def enum?(*types)
92
+ optional(enum(*types))
93
+ end
90
94
  end
91
95
  end
@@ -1,3 +1,3 @@
1
1
  class StrongJSON
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -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.6.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-03-26 00:00:00.000000000 Z
11
+ date: 2018-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler