strong_json 0.1.1 → 0.1.2
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 +5 -0
- data/lib/strong_json/type.rb +1 -1
- data/lib/strong_json/types.rb +8 -0
- data/lib/strong_json/version.rb +1 -1
- data/spec/object_spec.rb +12 -1
- 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: 4a009e9385e3e0d6dceed251b6951e533d8d9cae
|
4
|
+
data.tar.gz: 26c8e89826ebe9b88b325c647c662d7b89013ddf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d597908375f4112ee71f931f60a4c489ead56ae2c56c31fac8f185375aad38539ded3b846e8ce4207d32641f4641cccb244dc28ee8dcf20487f0dfb12108de5b
|
7
|
+
data.tar.gz: 643ca3880954ba6fd3f5ac9654313d604744c50f79142af703364281d1aab35d406b3610fced4b1ef0a79fc5a711d95fb03887c22cb7f77294d687b9d6898c79
|
data/README.md
CHANGED
@@ -75,6 +75,11 @@ There are some alias for `optional(base)`, where base is base types, as the foll
|
|
75
75
|
* `boolean?`
|
76
76
|
* `numeric?`
|
77
77
|
|
78
|
+
Shorthands for `optional(array(ty))` and `optional(object(fields))` are also defined as the following:
|
79
|
+
|
80
|
+
* `array?(ty)`
|
81
|
+
* `object?(fields)`
|
82
|
+
|
78
83
|
## Contributing
|
79
84
|
|
80
85
|
1. Fork it ( https://github.com/soutaro/strong_json/fork )
|
data/lib/strong_json/type.rb
CHANGED
data/lib/strong_json/types.rb
CHANGED
data/lib/strong_json/version.rb
CHANGED
data/spec/object_spec.rb
CHANGED
@@ -32,12 +32,23 @@ describe StrongJSON::Type::Object do
|
|
32
32
|
|
33
33
|
expect{ type.coerce(b: "test") }.to raise_error(StrongJSON::Type::Error)
|
34
34
|
end
|
35
|
+
end
|
35
36
|
|
37
|
+
describe "optional" do
|
36
38
|
it "accepts missing field if optional" do
|
37
39
|
type = StrongJSON::Type::Object.new(a: StrongJSON::Type::Optional.new(StrongJSON::Type::Base.new(:numeric)))
|
38
|
-
|
39
40
|
expect(type.coerce({})).to eq({})
|
40
41
|
end
|
42
|
+
|
43
|
+
it "preserves if present" do
|
44
|
+
type = StrongJSON::Type::Object.new(a: StrongJSON::Type::Optional.new(StrongJSON::Type::Base.new(:numeric)))
|
45
|
+
expect(type.coerce({ a: "-123" })).to eq({ a: "-123" })
|
46
|
+
end
|
47
|
+
|
48
|
+
it "preserves nil if present" do
|
49
|
+
type = StrongJSON::Type::Object.new(a: StrongJSON::Type::Optional.new(StrongJSON::Type::Base.new(:numeric)))
|
50
|
+
expect(type.coerce({ a: nil })).to eq({ a: nil })
|
51
|
+
end
|
41
52
|
end
|
42
53
|
|
43
54
|
describe "#merge" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strong_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Soutaro Matsumoto
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.2.2
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: Type check JSON objects
|