strong_json 0.2.0 → 0.3.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: 3740cb9d6923fabe6e9a14b191771d5dad7b5328
4
- data.tar.gz: d719d0f91add645572ed65a1e89167f357037621
3
+ metadata.gz: a0361a33f682e9ba1f121b0936ae8fe93f319cba
4
+ data.tar.gz: c4128c7ed52306c800078de3f5121c2fe9b951a3
5
5
  SHA512:
6
- metadata.gz: ee65118af560df40ffa22a18d3b30fe376eddb3282a999027df49e8d59d71a899dd49ae3fcdbc90fa4a0c1a239b14eee5e014aae161297e6c2a516f50419dae1
7
- data.tar.gz: dc7f9eae7a70b1d8967ead36cef902275908db9a7d2f83f204924a95d5c74cb6e4909c34061eb17f49782766d64989e2d6e811f211cc840a816528d5c288d02d
6
+ metadata.gz: 255f8a7b8e988dd081cb1ab82d916861b25effdc26bf854acbbaaad0eb3746751cc95756761e0eb8269202fd2ccd3a8160de52bcf99cbcdadd28a06224726cdf
7
+ data.tar.gz: 04e267544534ec7043132494c13c7cadba63b0e61f303445714bcf5207e85eabae0675eaababc099a5cdd1aa17f73640a0d5914c9de574badb9a203ca7f7809c
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.4.1
@@ -1,5 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "2.1.1"
4
- - "2.1.2"
5
- - "2.1.3"
3
+ - "2.3.3"
4
+ - "2.4.1"
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 :custoemr, object(name: string, address: string, phone: string, email: optional(string))
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.
@@ -9,6 +9,10 @@ class StrongJSON
9
9
  rescue
10
10
  false
11
11
  end
12
+
13
+ def ===(value)
14
+ self =~ value
15
+ end
12
16
  end
13
17
 
14
18
  class Base
@@ -1,3 +1,3 @@
1
1
  class StrongJSON
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -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.2.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: 2016-11-02 00:00:00.000000000 Z
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.5.1
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