strong_json 0.7.0 → 0.7.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 203acba136e0a5e13955cb71eaf772b437490bf1
4
- data.tar.gz: d7e81bffc189686f7d3ea48d5c589456aa30253b
2
+ SHA256:
3
+ metadata.gz: b38c3654e379c46a4b5567f8c256c72da14ca8efa3bd64deef2b56c4e037957d
4
+ data.tar.gz: b3b3832aa8b1e76a84c2210234f34b8abcecc02a3d42848ae871e648f41e35f8
5
5
  SHA512:
6
- metadata.gz: f1d96614ae765a7eb3287b51d83dfbdaf07384c2316e32f41bc38f4ff85beadb3248bd751f814fbe27b1049cf329a5c2365894781c1c398d0e606dbf179b3728
7
- data.tar.gz: 6fb5d0c5ed6b24c26994268c72d116bb7d70efd932648437bc644259a5828ec0c34ad1077466ffdb274e31e2805947b6638c76e4a75376efa4d823dc18972cce
6
+ metadata.gz: c2a949f49b357ffa0496bf1d6646d57190b6c26633ce604ef2cb30f6faf72b9d89de3b88172dac22776914b053eb5081c80a75bbdbf88217d1ff04d3bfdfe3c8
7
+ data.tar.gz: d74c050d81ee145056978925f475e216692c107536258306857b4379288318930fafecce803d9e02454cd7997ab3b925005019ddad6a098a9750c0db7b0276cf
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.1
1
+ 2.5.1
data/.travis.yml CHANGED
@@ -2,3 +2,4 @@ language: ruby
2
2
  rvm:
3
3
  - "2.3.3"
4
4
  - "2.4.1"
5
+ - "2.5.1"
@@ -80,7 +80,7 @@ class StrongJSON
80
80
  end
81
81
 
82
82
  def to_s
83
- "optinal(#{@type})"
83
+ "optional(#{@type})"
84
84
  end
85
85
  end
86
86
 
@@ -204,18 +204,14 @@ class StrongJSON
204
204
  end
205
205
 
206
206
  def coerce(value, path: [])
207
- result = types.find do |ty|
207
+ types.each do |ty|
208
208
  begin
209
- break ty.coerce(value)
209
+ return ty.coerce(value, path: path)
210
210
  rescue UnexpectedFieldError, IllegalTypeError, Error # rubocop:disable Lint/HandleExceptions
211
211
  end
212
212
  end
213
213
 
214
- if result
215
- result
216
- else
217
- raise Error.new(path: path, type: self, value: value)
218
- end
214
+ raise Error.new(path: path, type: self, value: value)
219
215
  end
220
216
  end
221
217
 
@@ -1,3 +1,3 @@
1
1
  class StrongJSON
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
data/spec/enum_spec.rb CHANGED
@@ -26,7 +26,9 @@ describe StrongJSON::Type::Enum do
26
26
  StrongJSON::Type::Object.new(id: StrongJSON::Type::Literal.new("id1"),
27
27
  value: StrongJSON::Type::Base.new(:string)),
28
28
  StrongJSON::Type::Object.new(id: StrongJSON::Type::Base.new(:string),
29
- value: StrongJSON::Type::Base.new(:symbol))
29
+ value: StrongJSON::Type::Base.new(:symbol)),
30
+ StrongJSON::Type::Optional.new(StrongJSON::Type::Literal.new(3)),
31
+ StrongJSON::Type::Literal.new(false),
30
32
  ])
31
33
  }
32
34
 
@@ -38,6 +40,14 @@ describe StrongJSON::Type::Enum do
38
40
  expect(type.coerce({id: "id2", value: "foo" })).to eq({ id: "id2", value: :foo })
39
41
  end
40
42
 
43
+ it "accepts false" do
44
+ expect(type.coerce(false)).to eq(false)
45
+ end
46
+
47
+ it "accepts nil" do
48
+ expect(type.coerce(nil)).to eq(nil)
49
+ end
50
+
41
51
  it "raises error" do
42
52
  expect { type.coerce(3.14) }.to raise_error(StrongJSON::Type::Error)
43
53
  end
data/spec/json_spec.rb CHANGED
@@ -12,14 +12,14 @@ describe "StrongJSON.new" do
12
12
 
13
13
  it "tests enums" do
14
14
  s = StrongJSON.new do
15
- let :enum, object(e1: enum(string, number), e2: enum?(literal(1), literal(2)))
15
+ let :enum, object(e1: enum(boolean, number), e2: enum?(literal(1), literal(2)))
16
16
  end
17
17
 
18
- expect(s.enum.coerce(e1: "")).to eq(e1: "")
18
+ expect(s.enum.coerce(e1: false)).to eq(e1: false)
19
19
  expect(s.enum.coerce(e1: 0)).to eq(e1: 0)
20
20
  expect(s.enum.coerce(e1: 0, e2: 1)).to eq(e1: 0, e2: 1)
21
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
22
  expect{ s.enum.coerce(e1: "", e2: 3) }.to raise_error(StrongJSON::Type::Error)
23
+ expect{ s.enum.coerce(e1: false, e2: "") }.to raise_error(StrongJSON::Type::Error)
24
24
  end
25
25
  end
data/strong_json.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["matsumoto@soutaro.com"]
11
11
  spec.summary = "Type check JSON objects"
12
12
  spec.description = "Type check JSON objects"
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/soutaro/strong_json"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
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.7.0
4
+ version: 0.7.1
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-08-27 00:00:00.000000000 Z
11
+ date: 2018-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,7 +80,7 @@ files:
80
80
  - spec/object_spec.rb
81
81
  - spec/optional_spec.rb
82
82
  - strong_json.gemspec
83
- homepage: ''
83
+ homepage: https://github.com/soutaro/strong_json
84
84
  licenses:
85
85
  - MIT
86
86
  metadata: {}
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.6.11
103
+ rubygems_version: 2.7.6
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: Type check JSON objects