strong_json 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +4 -0
- data/README.md +2 -0
- data/lib/strong_json/error_reporter.rb +1 -1
- data/lib/strong_json/type.rb +3 -1
- data/lib/strong_json/types.rb +8 -0
- data/lib/strong_json/version.rb +1 -1
- data/sig/strong_json.rbi +2 -0
- data/sig/type.rbi +1 -1
- data/spec/basetype_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7ff37c821f98f3d174d49ea2af07864e90ac844be26229647abda379b2f80f9
|
4
|
+
data.tar.gz: '05592b56d071c4eac6122667a432bfcfaf29559a10ccb854f12f450039c2b680'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c79a051b24b4fd914629974c67d5aaecf32ad31f65fcda56a5da70f8cb00f7cea89ca9cf4e310b796f6f13d347c39184d0daa63c15b695af92e7160f01719ed4
|
7
|
+
data.tar.gz: 1f66d80fe299618161438fa17f5632106a94b5e569e85da2fc82b1b8c38853a7eaaa0e46a19253fb0a5cc31b22356cb5921db120f3f51c78652750793e2ef0ba
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -117,6 +117,7 @@ enum(person,
|
|
117
117
|
### Base types
|
118
118
|
|
119
119
|
* `number` The value must be an instance of `Numeric`
|
120
|
+
* `integer` The value must be an instance of `Integer`
|
120
121
|
* `string` The value must be an instance of `String`
|
121
122
|
* `boolean` The value must be `true` or `false`
|
122
123
|
* `numeric` The value must be an instance of `Numeric` or a string which represents a number
|
@@ -132,6 +133,7 @@ enum(person,
|
|
132
133
|
There are some alias for `optional(base)`, where base is base types, as the following:
|
133
134
|
|
134
135
|
* `number?`
|
136
|
+
* `integer?`
|
135
137
|
* `string?`
|
136
138
|
* `boolean?`
|
137
139
|
* `numeric?`
|
data/lib/strong_json/type.rb
CHANGED
@@ -15,7 +15,7 @@ class StrongJSON
|
|
15
15
|
|
16
16
|
module WithAlias
|
17
17
|
def alias
|
18
|
-
@alias
|
18
|
+
defined?(@alias) ? @alias : nil
|
19
19
|
end
|
20
20
|
|
21
21
|
def with_alias(name)
|
@@ -44,6 +44,8 @@ class StrongJSON
|
|
44
44
|
true
|
45
45
|
when :number
|
46
46
|
value.is_a?(Numeric)
|
47
|
+
when :integer
|
48
|
+
value.is_a?(Integer)
|
47
49
|
when :string
|
48
50
|
value.is_a?(String)
|
49
51
|
when :boolean
|
data/lib/strong_json/types.rb
CHANGED
@@ -31,6 +31,10 @@ class StrongJSON
|
|
31
31
|
StrongJSON::Type::Base.new(:number)
|
32
32
|
end
|
33
33
|
|
34
|
+
def integer
|
35
|
+
StrongJSON::Type::Base.new(:integer)
|
36
|
+
end
|
37
|
+
|
34
38
|
def boolean
|
35
39
|
StrongJSON::Type::Base.new(:boolean)
|
36
40
|
end
|
@@ -63,6 +67,10 @@ class StrongJSON
|
|
63
67
|
optional(numeric)
|
64
68
|
end
|
65
69
|
|
70
|
+
def integer?
|
71
|
+
optional(integer)
|
72
|
+
end
|
73
|
+
|
66
74
|
def number?
|
67
75
|
optional(number)
|
68
76
|
end
|
data/lib/strong_json/version.rb
CHANGED
data/sig/strong_json.rbi
CHANGED
@@ -38,6 +38,8 @@ module StrongJSON::Types
|
|
38
38
|
def number?: () -> Type::Optional<Numeric>
|
39
39
|
def numeric: () -> Type::Base<Numeric>
|
40
40
|
def numeric?: () -> Type::Optional<Numeric>
|
41
|
+
def integer: () -> Type::Base<Integer>
|
42
|
+
def integer?: () -> Type::Optional<Integer>
|
41
43
|
def boolean: () -> Type::Base<bool>
|
42
44
|
def boolean?: () -> Type::Optional<bool>
|
43
45
|
def symbol: () -> Type::Base<Symbol>
|
data/sig/type.rbi
CHANGED
@@ -12,7 +12,7 @@ module StrongJSON::Type::WithAlias: ::Object
|
|
12
12
|
def with_alias: (Symbol) -> self
|
13
13
|
end
|
14
14
|
|
15
|
-
type StrongJSON::base_type_name = :any | :number | :string | :boolean | :numeric | :symbol
|
15
|
+
type StrongJSON::base_type_name = :any | :number | :string | :boolean | :numeric | :symbol | :integer
|
16
16
|
|
17
17
|
class StrongJSON::Type::Base<'a>
|
18
18
|
include Match
|
data/spec/basetype_spec.rb
CHANGED
@@ -94,6 +94,18 @@ describe StrongJSON::Type::Base do
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
+
context ":integer" do
|
98
|
+
let (:type) { StrongJSON::Type::Base.new(:integer) }
|
99
|
+
|
100
|
+
it "accepts integer" do
|
101
|
+
expect(type.test(123)).to be_truthy
|
102
|
+
end
|
103
|
+
|
104
|
+
it "rejects float" do
|
105
|
+
expect(type.test(1.23)).to be_falsey
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
97
109
|
context ":numeric" do
|
98
110
|
let (:type) { StrongJSON::Type::Base.new(:numeric) }
|
99
111
|
|
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: 2.
|
4
|
+
version: 2.1.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: 2019-
|
11
|
+
date: 2019-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|