strong_json 0.2.0 → 0.3.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/.ruby-version +1 -1
- data/.travis.yml +2 -3
- data/README.md +10 -1
- data/lib/strong_json/type.rb +4 -0
- data/lib/strong_json/version.rb +1 -1
- data/spec/case_subsumption_operator_spec.rb +25 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0361a33f682e9ba1f121b0936ae8fe93f319cba
|
4
|
+
data.tar.gz: c4128c7ed52306c800078de3f5121c2fe9b951a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 255f8a7b8e988dd081cb1ab82d916861b25effdc26bf854acbbaaad0eb3746751cc95756761e0eb8269202fd2ccd3a8160de52bcf99cbcdadd28a06224726cdf
|
7
|
+
data.tar.gz: 04e267544534ec7043132494c13c7cadba63b0e61f303445714bcf5207e85eabae0675eaababc099a5cdd1aa17f73640a0d5914c9de574badb9a203ca7f7809c
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.1
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -26,12 +26,21 @@ Or install it yourself as:
|
|
26
26
|
```ruby
|
27
27
|
s = StrongJSON.new do
|
28
28
|
let :item, object(id: prohibited, name: string, count: numeric)
|
29
|
-
let :
|
29
|
+
let :customer, object(name: string, address: string, phone: string, email: optional(string))
|
30
30
|
let :order, object(customer: customer, items: array(item))
|
31
31
|
end
|
32
32
|
|
33
33
|
json = s.order.coerce(JSON.parse(input), symbolize_names: true)
|
34
34
|
s.order =~ JSON.parse(input, symbolize_names: true)
|
35
|
+
|
36
|
+
case JSON.parse(input2, symbolize_names: true)
|
37
|
+
when s.item
|
38
|
+
# input2 is an item
|
39
|
+
when s.customer
|
40
|
+
# input2 is a customer
|
41
|
+
else
|
42
|
+
# input2 is something else
|
43
|
+
end
|
35
44
|
```
|
36
45
|
|
37
46
|
If the input JSON data conforms to `order`'s structure, the `json` will be that value.
|
data/lib/strong_json/type.rb
CHANGED
data/lib/strong_json/version.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "strong_json"
|
2
|
+
|
3
|
+
describe StrongJSON::Type do
|
4
|
+
let(:schema) { StrongJSON::Type::Literal.new(3) }
|
5
|
+
|
6
|
+
describe "===" do
|
7
|
+
it "tests by =~ and returns true" do
|
8
|
+
expect(
|
9
|
+
case 3
|
10
|
+
when schema
|
11
|
+
true
|
12
|
+
end
|
13
|
+
).to be_truthy
|
14
|
+
end
|
15
|
+
|
16
|
+
it "tests by =~ and returns false" do
|
17
|
+
expect(
|
18
|
+
case true
|
19
|
+
when schema
|
20
|
+
true
|
21
|
+
end
|
22
|
+
).to be_falsey
|
23
|
+
end
|
24
|
+
end
|
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.3.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:
|
11
|
+
date: 2017-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- lib/strong_json/version.rb
|
73
73
|
- spec/array_spec.rb
|
74
74
|
- spec/basetype_spec.rb
|
75
|
+
- spec/case_subsumption_operator_spec.rb
|
75
76
|
- spec/enum_spec.rb
|
76
77
|
- spec/error_spec.rb
|
77
78
|
- spec/json_spec.rb
|
@@ -99,13 +100,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
100
|
version: '0'
|
100
101
|
requirements: []
|
101
102
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
103
|
+
rubygems_version: 2.6.11
|
103
104
|
signing_key:
|
104
105
|
specification_version: 4
|
105
106
|
summary: Type check JSON objects
|
106
107
|
test_files:
|
107
108
|
- spec/array_spec.rb
|
108
109
|
- spec/basetype_spec.rb
|
110
|
+
- spec/case_subsumption_operator_spec.rb
|
109
111
|
- spec/enum_spec.rb
|
110
112
|
- spec/error_spec.rb
|
111
113
|
- spec/json_spec.rb
|