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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b06583a5049ceb64b418d9dbfa9d9b024487c116a2b84cda2effc8f20f47dfc
4
- data.tar.gz: 3998a14cfa6c87822c9d8da3d510c64cdb3ec8ca49762e104564c2109711ca8e
3
+ metadata.gz: a7ff37c821f98f3d174d49ea2af07864e90ac844be26229647abda379b2f80f9
4
+ data.tar.gz: '05592b56d071c4eac6122667a432bfcfaf29559a10ccb854f12f450039c2b680'
5
5
  SHA512:
6
- metadata.gz: 3eea214df1267ca23eb4ca45150c8a967c2f928738a225ccc1b42d2a5dbace87593d1ae8184554e47e40012f3e694b5c8f333a58dcb90fb680e73401b5dd49b6
7
- data.tar.gz: 5e974fe31499668b39a8dd953267f2a7ef2ea0b070dcc1c48dfa14b7c1ac33df5a57d7dd20a039bfe1cd16dfa52de0a91c8c8a1bc3445fd48b092b007437d827
6
+ metadata.gz: c79a051b24b4fd914629974c67d5aaecf32ad31f65fcda56a5da70f8cb00f7cea89ca9cf4e310b796f6f13d347c39184d0daa63c15b695af92e7160f01719ed4
7
+ data.tar.gz: 1f66d80fe299618161438fa17f5632106a94b5e569e85da2fc82b1b8c38853a7eaaa0e46a19253fb0a5cc31b22356cb5921db120f3f51c78652750793e2ef0ba
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  /.bundle/
2
+ /vendor/bundle/
2
3
  /.yardoc
3
4
  /Gemfile.lock
4
5
  /_yardoc/
@@ -1,3 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - "2.5.3"
4
+ - "2.6.3"
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 2.1.0 (2019-07-19)
6
+
7
+ * [20](https://github.com/soutaro/strong_json/pull/20): Add `integer` type
8
+
5
9
  ## 2.0.0 (2019-06-28)
6
10
 
7
11
  * [17](https://github.com/soutaro/strong_json/pull/17): Revise `Object` type _ignore_/_reject_ API
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?`
@@ -8,7 +8,7 @@ class StrongJSON
8
8
  end
9
9
 
10
10
  def to_s
11
- format() unless @string
11
+ format() unless defined?(@string)
12
12
  @string
13
13
  end
14
14
 
@@ -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
@@ -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
@@ -1,5 +1,5 @@
1
1
  class StrongJSON
2
2
  # @dynamic initialize, let
3
3
 
4
- VERSION = "2.0.0"
4
+ VERSION = "2.1.0"
5
5
  end
@@ -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>
@@ -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
@@ -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.0.0
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-06-28 00:00:00.000000000 Z
11
+ date: 2019-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler