kind 5.7.0 → 5.10.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: a01866d3dbb6b0ae5977a7e711b35eaa2152471b4d52781a285de03ec9ef86a1
4
- data.tar.gz: 8fd0cc81e96aa364a90f3c161e824d1a501296b4c4b40e2aca1e4286a75baaec
3
+ metadata.gz: db0a2008eeb0137d93f74239fc4731ee7cc217a5714a30b9e57305e0d2a5b10a
4
+ data.tar.gz: 3b5efef522cc08fdd856ea4a9e3197eaef10c887a335479cac3a70cc67012ec6
5
5
  SHA512:
6
- metadata.gz: 10282e2b8777f2d1a738a6ce38285fc9f17f0d9a6b3aec26d46409d995cb0004fde5c20a3998ef68a98530c5fa25ee463fba8f3501e5cbeb0cb2b01e0f2627ba
7
- data.tar.gz: 7d16bf63dbb4928bef6182a7886e9268da869bddab12ac0e1192e39bac3fce2a4489ed308366188df4d6550047b2003e1b427f87430ec5e68c49c34a3974c13f
6
+ metadata.gz: 2ded2725b6df3fee68cb30df6aa3172d2b16493f7071314a8be8dc0345dd450461ba899defad6af62073569e83348108f6ac6bbd7699ddc3c47c9e4ea9107069
7
+ data.tar.gz: d724177aa2643868ef4ff5700c51d228209aa1f40ca756a3670f8ddb5f769af61a8a14f7433a04a9d7f9451deda73b60b91739c0e7a153a03d4eabde20ba24b3
@@ -0,0 +1,27 @@
1
+
2
+ name: build
3
+ on: [pull_request]
4
+ jobs:
5
+ test:
6
+ runs-on: ubuntu-latest
7
+ strategy:
8
+ matrix:
9
+ ruby: [2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 3.0]
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: ${{ matrix.ruby }}
15
+ bundler-cache: true
16
+ - name: Test and generate coverage
17
+ run: bin/test
18
+ - name: Format coverage
19
+ if: ${{ matrix.ruby >= 3 }}
20
+ run: bin/prepare_coverage
21
+ - uses: paambaati/codeclimate-action@v2.7.5
22
+ if: ${{ matrix.ruby >= 3 }}
23
+ env:
24
+ CC_TEST_REPORTER_ID: 9561ceed21b6724aea8063e82e5700bc8266e962978089594bf2d8f8ca5ffc94
25
+ with:
26
+ debug: true
27
+ coverageLocations: coverage/.resultset.json:simplecov
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  Gemfile.lock
11
11
  .foo
12
+ .tool-versions
@@ -0,0 +1,8 @@
1
+ {
2
+ "cSpell.enabled": true,
3
+ "cSpell.ignoreWords": [
4
+ "paambaati",
5
+ "resultset",
6
+ "simplecov"
7
+ ]
8
+ }
data/CHANGELOG.md CHANGED
@@ -3,85 +3,93 @@
3
3
  This project follows [semver 2.0.0](http://semver.org/spec/v2.0.0.html) and the recommendations of [keepachangelog.com](http://keepachangelog.com/).
4
4
 
5
5
  - [Unreleased](#unreleased)
6
- - [5.7.0 (2021-06-22)](#570-2021-06-22)
6
+ - [5.10.0 (2021-09-23)](#5100-2021-09-23)
7
7
  - [Added](#added)
8
- - [5.6.0 (2021-05-14)](#560-2021-05-14)
8
+ - [5.9.0 (2021-09-22)](#590-2021-09-22)
9
9
  - [Added](#added-1)
10
- - [5.5.0 (2021-04-05)](#550-2021-04-05)
10
+ - [5.8.1 (2021-09-22)](#581-2021-09-22)
11
+ - [Fixed](#fixed)
12
+ - [5.8.0 (2021-09-22)](#580-2021-09-22)
11
13
  - [Added](#added-2)
14
+ - [5.7.0 (2021-06-22)](#570-2021-06-22)
15
+ - [Added](#added-3)
16
+ - [5.6.0 (2021-05-14)](#560-2021-05-14)
17
+ - [Added](#added-4)
18
+ - [5.5.0 (2021-04-05)](#550-2021-04-05)
19
+ - [Added](#added-5)
12
20
  - [5.4.1 (2021-03-26)](#541-2021-03-26)
13
- - [Fixed](#fixed)
21
+ - [Fixed](#fixed-1)
14
22
  - [5.4.0 (2021-03-25)](#540-2021-03-25)
15
- - [Added](#added-3)
23
+ - [Added](#added-6)
16
24
  - [5.3.0 (2021-03-23)](#530-2021-03-23)
17
- - [Added](#added-4)
25
+ - [Added](#added-7)
18
26
  - [5.2.0 (2021-03-17)](#520-2021-03-17)
19
- - [Added](#added-5)
27
+ - [Added](#added-8)
20
28
  - [Deprecated](#deprecated)
21
29
  - [Changes](#changes)
22
30
  - [5.1.0 (2021-02-23)](#510-2021-02-23)
23
- - [Added](#added-6)
31
+ - [Added](#added-9)
24
32
  - [Deprecated](#deprecated-1)
25
33
  - [5.0.0 (2021-02-22)](#500-2021-02-22)
26
34
  - [Breaking Changes](#breaking-changes)
27
35
  - [Removed](#removed)
28
36
  - [4.1.0 (2021-02-22)](#410-2021-02-22)
29
- - [Added](#added-7)
37
+ - [Added](#added-10)
30
38
  - [4.0.0 (2021-02-22)](#400-2021-02-22)
31
- - [Added](#added-8)
39
+ - [Added](#added-11)
32
40
  - [Deprecated](#deprecated-2)
33
- - [Fixed](#fixed-1)
41
+ - [Fixed](#fixed-2)
34
42
  - [3.1.0 (2020-07-08)](#310-2020-07-08)
35
- - [Added](#added-9)
43
+ - [Added](#added-12)
36
44
  - [3.0.0 (2020-06-25)](#300-2020-06-25)
37
45
  - [Breaking Changes](#breaking-changes-1)
38
- - [Added](#added-10)
46
+ - [Added](#added-13)
39
47
  - [2.3.0 (2020-06-24)](#230-2020-06-24)
40
- - [Added](#added-11)
48
+ - [Added](#added-14)
41
49
  - [2.2.0 (2020-06-23)](#220-2020-06-23)
42
- - [Added](#added-12)
50
+ - [Added](#added-15)
43
51
  - [2.1.0 (2020-05-12)](#210-2020-05-12)
44
- - [Added](#added-13)
52
+ - [Added](#added-16)
45
53
  - [Breaking Changes](#breaking-changes-2)
46
54
  - [2.0.0 (2020-05-07)](#200-2020-05-07)
47
- - [Added](#added-14)
55
+ - [Added](#added-17)
48
56
  - [Breaking Changes](#breaking-changes-3)
49
57
  - [Removed](#removed-1)
50
58
  - [1.9.0 (2020-05-06)](#190-2020-05-06)
51
- - [Added](#added-15)
59
+ - [Added](#added-18)
52
60
  - [1.8.0 (2020-05-03)](#180-2020-05-03)
53
- - [Added](#added-16)
61
+ - [Added](#added-19)
54
62
  - [1.7.0 (2020-05-03)](#170-2020-05-03)
55
- - [Fixed](#fixed-2)
63
+ - [Fixed](#fixed-3)
56
64
  - [1.6.0 (2020-04-17)](#160-2020-04-17)
57
- - [Added](#added-17)
65
+ - [Added](#added-20)
58
66
  - [Changes](#changes-1)
59
67
  - [1.5.0 (2020-04-12)](#150-2020-04-12)
60
- - [Added](#added-18)
68
+ - [Added](#added-21)
61
69
  - [1.4.0 (2020-04-12)](#140-2020-04-12)
62
- - [Added](#added-19)
70
+ - [Added](#added-22)
63
71
  - [1.3.0 (2020-04-12)](#130-2020-04-12)
64
- - [Added](#added-20)
72
+ - [Added](#added-23)
65
73
  - [1.2.0 (2020-04-12)](#120-2020-04-12)
66
- - [Added](#added-21)
74
+ - [Added](#added-24)
67
75
  - [1.1.0 (2020-04-09)](#110-2020-04-09)
68
- - [Added](#added-22)
69
- - [Fixed](#fixed-3)
76
+ - [Added](#added-25)
77
+ - [Fixed](#fixed-4)
70
78
  - [1.0.0 (2020-03-16)](#100-2020-03-16)
71
- - [Added](#added-23)
79
+ - [Added](#added-26)
72
80
  - [0.6.0 (2020-01-06)](#060-2020-01-06)
73
- - [Added](#added-24)
81
+ - [Added](#added-27)
74
82
  - [0.5.0 (2020-01-04)](#050-2020-01-04)
75
- - [Added](#added-25)
83
+ - [Added](#added-28)
76
84
  - [0.4.0 (2020-01-03)](#040-2020-01-03)
77
- - [Added](#added-26)
85
+ - [Added](#added-29)
78
86
  - [0.3.0 (2020-01-03)](#030-2020-01-03)
79
- - [Added](#added-27)
87
+ - [Added](#added-30)
80
88
  - [Breaking Changes](#breaking-changes-4)
81
89
  - [0.2.0 (2020-01-02)](#020-2020-01-02)
82
- - [Added](#added-28)
90
+ - [Added](#added-31)
83
91
  - [0.1.0 (2019-12-26)](#010-2019-12-26)
84
- - [Added](#added-29)
92
+ - [Added](#added-32)
85
93
 
86
94
  ## Unreleased
87
95
 
@@ -93,6 +101,197 @@ This project follows [semver 2.0.0](http://semver.org/spec/v2.0.0.html) and the
93
101
  ### Fixed
94
102
  -->
95
103
 
104
+ 5.10.0 (2021-09-23)
105
+ ------------------
106
+
107
+ ### Added
108
+
109
+ * [#69](https://github.com/serradura/kind/pull/69) - Make `Kind::Any` works with a `Set`.
110
+ ```ruby
111
+ require 'kind/any'
112
+
113
+ Kind::Any.new(Set[:low, :high]).inspect # Kind::Any{:low, :high}
114
+
115
+ Kind::Any.new(Array['open', 'close']).inspect # Kind::Any["open", "close"]
116
+ ```
117
+
118
+ [⬆️  Back to Top](#changelog-)
119
+
120
+ 5.9.0 (2021-09-22)
121
+ ------------------
122
+
123
+ ### Added
124
+
125
+ * [#68](https://github.com/serradura/kind/pull/68) - Add `Kind.object(name:, &block)` to create `Kind::Objects`.
126
+ ```ruby
127
+ PositiveInteger = Kind.object(name: 'PositiveInteger') do |value|
128
+ value.kind_of?(Integer) && value > 0
129
+ end
130
+
131
+ # PositiveInteger.name
132
+ # PositiveInteger.kind
133
+ # The type handler can return its kind and its name
134
+ PositiveInteger.name # "PositiveInteger"
135
+ PositiveInteger.kind # #<Proc:0x0000.... >
136
+
137
+ # PositiveInteger.===
138
+ # Can check if a given value is an instance of its kind.
139
+ PositiveInteger === 1 # true
140
+ PositiveInteger === 0 # false
141
+
142
+ # PositiveInteger.value?(value)
143
+ # Can check if a given value is an instance of its kind.
144
+ PositiveInteger.value?(1) # true
145
+ PositiveInteger.value?(-1) # false
146
+
147
+ # If it doesn't receive an argument, a lambda will be returned and it will know how to do the type verification.
148
+ [1, 2, 0, 3, -1].select(&PositiveInteger.value?) # [1, 2, 3]
149
+
150
+ # PositiveInteger.or_nil(value)
151
+ # Can return nil if the given value isn't an instance of its kind
152
+ PositiveInteger.or_nil(1) # 1
153
+ PositiveInteger.or_nil(0) # nil
154
+
155
+ # PositiveInteger.or_undefined(value)
156
+ # Can return Kind::Undefined if the given value isn't an instance of its kind
157
+ PositiveInteger.or_undefined(2) # 2
158
+ PositiveInteger.or_undefined(-1) # Kind::Undefined
159
+
160
+ # PositiveInteger.or(fallback, value)
161
+ # Can return a fallback if the given value isn't an instance of its kind
162
+ PositiveInteger.or(nil, 1) # 1
163
+ PositiveInteger.or(nil, 0) # nil
164
+
165
+ # If it doesn't receive a second argument (the value), it will return a callable that knows how to expose an instance of the expected type or a fallback if the given value was wrong.
166
+ [1, 2, 0, 3, -1].map(&PositiveInteger.or(1)) # [1, 2, 1, 3, 1]
167
+ [1, 2, 0, 3, -1].map(&PositiveInteger.or(nil)) # [1, 2, nil, 3, nil]
168
+
169
+ # An error will be raised if the fallback didn't have the expected kind or if not nil / Kind::Undefined.
170
+ [1, 2, 0, 3, -1].map(&PositiveInteger.or(:foo)) # Kind::Error (:foo expected to be a kind of PositiveInteger)
171
+
172
+ # PositiveInteger[value]
173
+ # Will raise Kind::Error if the given value isn't an instance of the expected kind
174
+ PositiveInteger[1] # 1
175
+ PositiveInteger[:foo] # Kind::Error (:foo expected to be a kind of PositiveInteger)
176
+
177
+ # PositiveInteger.value(arg, default:)
178
+ # This method ensures that you will have a value of the expected kind. But, in the case of the given value be invalid, this method will require a default value (with the expected kind) to be returned.
179
+ PositiveInteger.value(2, default: 1) # 2
180
+
181
+ PositiveInteger.value('1', default: 1) # 1
182
+
183
+ PositiveInteger.value('1', default: 0) # Kind::Error (0 expected to be a kind of PositiveInteger)
184
+
185
+ # PositiveInteger.maybe
186
+ # This method returns a typed Kind::Maybe.
187
+ PositiveInteger.maybe(0).value_or(1) # 1
188
+
189
+ PositiveInteger.maybe(2).value_or(1) # 2
190
+ ```
191
+
192
+ [⬆️ &nbsp;Back to Top](#changelog-)
193
+
194
+ 5.8.1 (2021-09-22)
195
+ ------------------
196
+
197
+ ### Fixed
198
+
199
+ * [#67](https://github.com/serradura/kind/pull/67) - Make `Kind.assert_hash!(some_hash, schema:)` works with a `Kind::Any` instance.
200
+ ```ruby
201
+ require 'kind/any'
202
+
203
+ Level = Kind::Any[:low, :high]
204
+
205
+ Kind.assert_hash!({level: :medium}, schema: {level: Level})
206
+ # Kind::Error (The key :status has an invalid value. Expected: Kind::Any[:low, :high])
207
+ ```
208
+
209
+ [⬆️ &nbsp;Back to Top](#changelog-)
210
+
211
+ 5.8.0 (2021-09-22)
212
+ ------------------
213
+
214
+ ### Added
215
+
216
+ * [#66](https://github.com/serradura/kind/pull/66) - Add `Kind::Any` to make easier the verification of a value in a list (array) of expected values.
217
+ ```ruby
218
+ require 'kind/any'
219
+
220
+ Level = Kind::Any[:low, :high] # or Kind::Any.new([:low, :high])
221
+
222
+ Level === :low # true
223
+ Level === :high # true
224
+
225
+ Level === :foo # false
226
+
227
+ Level[:low] # :low
228
+ Level[:high] # :high
229
+
230
+ Level[:foo] # Kind::Error (:foo expected to be a kind of Kind::Any[:low, :high])
231
+
232
+ level_or_any_symbol = # (Kind::Any[:low, :high] | Symbol)
233
+
234
+ Level.name # 'Kind::Any[:low, :high]'
235
+ Level.inspect # 'Kind::Any[:low, :high]'
236
+
237
+ Level.values # [:low, :high]
238
+ ```
239
+
240
+ * [#66](https://github.com/serradura/kind/pull/66) - Add `Kind::Enum.from_array(arg, use_index_as_value:)` to allow the creation of enums where its values will be the array values.
241
+ ```ruby
242
+ require 'kind/enum'
243
+
244
+ module Level
245
+ include Kind::Enum.from_array([:low, :medium, :high], use_index_as_value: false)
246
+ end
247
+
248
+ Level.keys # ["low", "medium", "high"]
249
+ Level.values # [:low, :medium, :high]
250
+
251
+ # ---
252
+
253
+ module Status
254
+ include Kind::Enum.from_array([:open, :closed], use_index_as_value: true)
255
+ end
256
+
257
+ Status.keys # ["open", "closed"]
258
+ Status.values # [0, 1]
259
+ ```
260
+
261
+ * [#66](https://github.com/serradura/kind/pull/66) - Make `Kind.assert_hash!(hash, schema:)` works with a `Kind::Object`.
262
+ ```ruby
263
+ FilledString = begin
264
+ filled_string = ->(value) {value.is_a?(String) && value.present?}
265
+
266
+ Kind[filled_string, name: 'FilledString']
267
+ end
268
+
269
+ Kind.assert_hash!(some_hash, schema: {
270
+ string: FilledString,
271
+ callable: Kind::Callable,
272
+ })
273
+ ```
274
+
275
+ * [#66](https://github.com/serradura/kind/pull/66) - Improve the exception messages of `Kind.assert_hash!(hash, schema:)`.
276
+ ```ruby
277
+ Kind.assert_hash!({status: 1}, schema: {status: Kind::String | Symbol})
278
+ # Kind::Error (The key :status has an invalid value. Expected: (String | Symbol))
279
+
280
+ Kind.assert_hash!({status: 'closed'}, schema: {status: 'active'})
281
+ # Kind::Error (The key :status has an invalid value. Expected: active, Given: closed)
282
+
283
+ Kind.assert_hash!({callable: 1}, schema: {callable: Kind::Callable})
284
+ # Kind::Error (The key :callable has an invalid value. Expected: Callable)
285
+ ```
286
+
287
+ * [#66](https://github.com/serradura/kind/pull/66) - Make `Kind.assert_hash!(hash, **options)` raises an error if the given hash be empty.
288
+ ```ruby
289
+ Kind.assert_hash!({}, keys: []) # ArgumentError (hash can't be empty)
290
+ Kind.assert_hash!({}, schema: {}) # ArgumentError (hash can't be empty)
291
+ ```
292
+
293
+ [⬆️ &nbsp;Back to Top](#changelog-)
294
+
96
295
  5.7.0 (2021-06-22)
97
296
  ------------------
98
297
 
data/Gemfile CHANGED
@@ -20,7 +20,7 @@ simplecov_version =
20
20
  case RUBY_VERSION
21
21
  when /\A2.[123]/ then '0.17.1'
22
22
  when /\A2.4/ then '~> 0.18.5'
23
- else '~> 0.19'
23
+ else '~> 0.21.2'
24
24
  end
25
25
 
26
26
  is_ruby_2_1 = RUBY_VERSION <= '2.2.0'
data/README.md CHANGED
@@ -8,8 +8,8 @@
8
8
  <img alt="Gem" src="https://img.shields.io/gem/v/kind.svg?style=flat-square">
9
9
  </a>
10
10
 
11
- <a href="https://travis-ci.com/serradura/kind">
12
- <img alt="Build Status" src="https://travis-ci.com/serradura/kind.svg?branch=master">
11
+ <a href="https://github.com/serradura/kind/actions/workflows/ci.yml">
12
+ <img alt="Build Status" src="https://github.com/serradura/kind/actions/workflows/ci.yml/badge.svg">
13
13
  </a>
14
14
 
15
15
  <br />
@@ -42,7 +42,7 @@ So, I invite you to check out these features to see how they could be useful for
42
42
  Version | Documentation
43
43
  ---------- | -------------
44
44
  unreleased | https://github.com/serradura/kind/blob/main/README.md
45
- 5.7.0 | https://github.com/serradura/kind/blob/v5.x/README.md
45
+ 5.10.0 | https://github.com/serradura/kind/blob/v5.x/README.md
46
46
  4.1.0 | https://github.com/serradura/kind/blob/v4.x/README.md
47
47
  3.1.0 | https://github.com/serradura/kind/blob/v3.x/README.md
48
48
  2.3.0 | https://github.com/serradura/kind/blob/v2.x/README.md
@@ -69,7 +69,7 @@ unreleased | https://github.com/serradura/kind/blob/main/README.md
69
69
  - [Creating type handlers](#creating-type-handlers)
70
70
  - [Dynamic creation](#dynamic-creation)
71
71
  - [Using a class or a module](#using-a-class-or-a-module)
72
- - [Using an object which responds to ===](#using-an-object-which-responds-to-)
72
+ - [Using Kind.object(name:, &block)](#using-kindobjectname-block)
73
73
  - [Kind::<Type> object](#kindtype-object)
74
74
  - [Utility methods](#utility-methods)
75
75
  - [Kind.of_class?()](#kindof_class)
@@ -125,7 +125,7 @@ unreleased | https://github.com/serradura/kind/blob/main/README.md
125
125
  | kind | branch | ruby | activemodel |
126
126
  | -------------- | ------- | ------------------ | -------------- |
127
127
  | unreleased | main | >= 2.1.0, <= 3.0.0 | >= 3.2, < 7.0 |
128
- | 5.7.0 | v5.x | >= 2.1.0, <= 3.0.0 | >= 3.2, < 7.0 |
128
+ | 5.10.0 | v5.x | >= 2.1.0, <= 3.0.0 | >= 3.2, < 7.0 |
129
129
  | 4.1.0 | v4.x | >= 2.2.0, <= 3.0.0 | >= 3.2, < 7.0 |
130
130
  | 3.1.0 | v3.x | >= 2.2.0, <= 2.7 | >= 3.2, < 7.0 |
131
131
  | 2.3.0 | v2.x | >= 2.2.0, <= 2.7 | >= 3.2, <= 6.0 |
@@ -393,7 +393,7 @@ end
393
393
 
394
394
  user = User.new
395
395
 
396
- kind_of_user = Kind::Of(User)
396
+ kind_of_user = Kind[User]
397
397
 
398
398
  # kind_of_user.name
399
399
  # kind_of_user.kind
@@ -412,7 +412,7 @@ kind_of_user.value?('') # false
412
412
  kind_of_user.value?(User.new) # true
413
413
 
414
414
  # If it doesn't receive an argument, a lambda will be returned and it will know how to do the type verification.
415
- [0, User.new].select?(&kind_of_user.value?) # [#<User:0x0000.... >]
415
+ [0, User.new].select(&kind_of_user.value?) # [#<User:0x0000.... >]
416
416
 
417
417
  # kind_of_user.or_nil(value)
418
418
  # Can return nil if the given value isn't an instance of its kind
@@ -455,15 +455,12 @@ kind_of_user.maybe('1').value_or(User.new) # #<User:0x0000...>
455
455
 
456
456
  [⬆️ &nbsp;Back to Top](#table-of-contents-)
457
457
 
458
- ##### Using an object which responds to ===
459
-
460
- Example using a lambda (an object which responds to .===) and a hash with the kind name.
458
+ ##### Using Kind.object(name:, &block)
461
459
 
462
460
  ```ruby
463
- PositiveInteger = Kind::Of(
464
- -> value { value.kind_of?(Integer) && value > 0 },
465
- name: 'PositiveInteger'
466
- )
461
+ PositiveInteger = Kind.object(name: 'PositiveInteger') do |value|
462
+ value.kind_of?(Integer) && value > 0
463
+ end
467
464
 
468
465
  # PositiveInteger.name
469
466
  # PositiveInteger.kind
@@ -482,7 +479,7 @@ PositiveInteger.value?(1) # true
482
479
  PositiveInteger.value?(-1) # false
483
480
 
484
481
  # If it doesn't receive an argument, a lambda will be returned and it will know how to do the type verification.
485
- [1, 2, 0, 3, -1].select?(&PositiveInteger.value?) # [1, 2, 3]
482
+ [1, 2, 0, 3, -1].select(&PositiveInteger.value?) # [1, 2, 3]
486
483
 
487
484
  # PositiveInteger.or_nil(value)
488
485
  # Can return nil if the given value isn't an instance of its kind
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ # Borrowed from https://gist.github.com/qortex/7e7c49f3731391a91ee898336183acef
4
+
5
+ # Temporary hack to get CodeClimate to work with SimpleCov 0.18 JSON format until issue is fixed
6
+ # upstream: https://github.com/codeclimate/test-reporter/issues/413
7
+
8
+ require "json"
9
+
10
+ filename = "coverage/.resultset.json"
11
+ contents = JSON.parse(File.read(filename))
12
+
13
+ def remove_lines_key(obj)
14
+ case obj
15
+ when Hash
16
+ obj.transform_values do |val|
17
+ val.is_a?(Hash) && val.key?("lines") ? val["lines"] : remove_lines_key(val)
18
+ end
19
+ else
20
+ obj
21
+ end
22
+ end
23
+
24
+ # overwrite
25
+ File.write(filename, JSON.generate(remove_lines_key(contents)))
26
+
27
+ puts Dir['coverage/.*.json']
data/bin/test ADDED
@@ -0,0 +1,76 @@
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ RUBY_V=$(ruby -v)
6
+
7
+ function reset_gemfile_and_test {
8
+ rm Gemfile.lock
9
+
10
+ eval "$1 bundle update"
11
+ eval "$1 bundle exec rake test"
12
+ }
13
+
14
+ function test_with_activemodel {
15
+ reset_gemfile_and_test "ACTIVEMODEL_VERSION=$1"
16
+ }
17
+
18
+ function run_tests_by_modules {
19
+ rm Gemfile.lock
20
+
21
+ bundle update
22
+
23
+ eval "KIND_BASIC=t bundle exec rake test TEST='test/kind/{basic/*_test,basic_test}.rb'"
24
+ eval "KIND_BASIC=t bundle exec rake test TEST='test/kind/enum_test.rb'"
25
+ eval "KIND_BASIC=t bundle exec rake test TEST='test/kind/presence_test.rb'"
26
+ eval "KIND_BASIC=t bundle exec rake test TEST='test/kind/dig_test.rb'"
27
+ eval "KIND_BASIC=t bundle exec rake test TEST='test/kind/try_test.rb'"
28
+ eval "KIND_BASIC=t bundle exec rake test TEST='test/kind/maybe_test.rb'"
29
+ eval "KIND_BASIC=t bundle exec rake test TEST='test/kind/immutable_attributes_test.rb'"
30
+ eval "KIND_BASIC=t bundle exec rake test TEST='test/kind/function_test.rb'"
31
+ eval "KIND_BASIC=t bundle exec rake test TEST='test/kind/action_test.rb'"
32
+ eval "KIND_BASIC=t bundle exec rake test TEST='test/kind/{functional/*_test,functional_test}.rb'"
33
+ eval "KIND_BASIC=t bundle exec rake test TEST='test/kind/either/*_test.rb'"
34
+ eval "KIND_BASIC=t bundle exec rake test TEST='test/kind/result/*_test.rb'"
35
+
36
+ eval "KIND_STRICT=t bundle exec rake test TEST='test/kind/strict_disabled_test.rb'"
37
+ }
38
+
39
+ RUBY_2_12345="ruby 2.[12345]."
40
+ RUBY_2_2345="ruby 2.[2345]."
41
+ RUBY_2_1234="ruby 2.[1234]."
42
+ RUBY_2_567="ruby 2.[567]."
43
+ RUBY_2_12="ruby 2.[12]."
44
+ RUBY_3_X="ruby 3.0."
45
+
46
+ if [[ $RUBY_V =~ $RUBY_2_12345 ]]; then
47
+ if [[ $RUBY_V =~ $RUBY_2_12 ]]; then
48
+ test_with_activemodel "3.2"
49
+ fi
50
+
51
+ if [[ $RUBY_V =~ $RUBY_2_2345 ]]; then
52
+ test_with_activemodel "4.0"
53
+ test_with_activemodel "4.1"
54
+ test_with_activemodel "4.2"
55
+ test_with_activemodel "5.0"
56
+ test_with_activemodel "5.1"
57
+ test_with_activemodel "5.2"
58
+ fi
59
+
60
+ if [[ $RUBY_V =~ $RUBY_2_1234 ]]; then
61
+ run_tests_by_modules
62
+
63
+ reset_gemfile_and_test
64
+ fi
65
+ fi
66
+
67
+ if [[ $RUBY_V =~ $RUBY_2_567 ]] || [[ $RUBY_V =~ $RUBY_3_X ]]; then
68
+ gem install bundler -v ">= 2" --no-doc
69
+
70
+ test_with_activemodel "6.0"
71
+ test_with_activemodel "6.1"
72
+
73
+ run_tests_by_modules
74
+
75
+ reset_gemfile_and_test
76
+ fi
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kind
4
+ module AssertHash
5
+ module Keys
6
+ def self.require_all(keys, hash)
7
+ expected_keys = keys - hash.keys
8
+
9
+ unless expected_keys.empty?
10
+ raise KeyError.new("#{hash.inspect} expected to have these keys: #{expected_keys}")
11
+ end
12
+
13
+ unexpected_keys = hash.keys - keys
14
+
15
+ unless unexpected_keys.empty?
16
+ raise KeyError.new("#{hash.inspect} expected to NOT have these keys: #{unexpected_keys}")
17
+ end
18
+
19
+ hash
20
+ end
21
+ end
22
+
23
+ module Schema
24
+ extend self
25
+
26
+ KindAny = ->(value) { defined?(Kind::Any) ? Kind::Any === value : false }
27
+ KindObject = ->(value) { defined?(Kind::Object) ? Kind::Object === value : false }
28
+ KindUnionType = ->(value) { defined?(Kind::UnionType) ? Kind::UnionType === value : false }
29
+
30
+ def any(hash, spec)
31
+ spec.each do |key, expected|
32
+ value = hash[key]
33
+ error_message = "The key #{key.inspect} has an invalid value"
34
+
35
+ case expected
36
+ when KindAny, KindObject, KindUnionType then assert_kind_object(expected, value, error_message)
37
+ when ::Module then assert_kind_of(expected, value, error_message)
38
+ when ::Proc then assert(expected.call(value), error_message)
39
+ when ::Regexp then assert_match(expected, value, error_message)
40
+ when ::NilClass then assert_nil(value, error_message)
41
+ else assert_equal(expected, value, error_message)
42
+ end
43
+ end
44
+
45
+ hash
46
+ end
47
+
48
+ def all(hash, spec)
49
+ Keys.require_all(spec.keys, hash)
50
+
51
+ any(hash, spec)
52
+ end
53
+
54
+ private
55
+
56
+ def assert_equal(expected, value, message)
57
+ raise_kind_error("#{message}. Expected: #{expected.inspect}, Given: #{value.inspect}") if expected != value
58
+ end
59
+
60
+ def assert(value, message)
61
+ raise_kind_error(message) unless value
62
+ end
63
+
64
+ def assert_nil(value, message)
65
+ raise_kind_error("#{message}. Expected: nil") unless value.nil?
66
+ end
67
+
68
+ def assert_match(expected, value, message)
69
+ STRICT.kind_of(String, value)
70
+
71
+ raise_kind_error("#{message}. Expected: #{expected.inspect}") if value !~ expected
72
+ end
73
+
74
+ def assert_kind_of(expected, value, message)
75
+ raise_kind_error("#{message}. Expected: #{expected.inspect}") unless expected === value
76
+ end
77
+
78
+ def assert_kind_object(expected, value, message)
79
+ raise_kind_error("#{message}. Expected: #{expected.name}") unless expected === value
80
+ end
81
+
82
+
83
+ def raise_kind_error(message)
84
+ raise Error.new(message)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -6,16 +6,16 @@ module Kind
6
6
  module STRICT
7
7
  extend self
8
8
 
9
- require 'kind/__lib__/assert_hash_schema'
9
+ require 'kind/__lib__/assert_hash'
10
10
 
11
11
  def error(kind_name, value, label = nil) # :nodoc:
12
12
  raise Error.new(kind_name, value, label: label)
13
13
  end
14
14
 
15
- def object_is_a(kind, value, label = nil) # :nodoc:
15
+ def object_is_a(kind, value, label = nil, expected = nil) # :nodoc:
16
16
  return value if kind === value
17
17
 
18
- error(kind.name, value, label)
18
+ error(expected || kind.name, value, label)
19
19
  end
20
20
 
21
21
  def kind_of(kind, value, kind_name = nil) # :nodoc:
@@ -53,12 +53,17 @@ module Kind
53
53
  end
54
54
 
55
55
  def assert_hash!(hash, options)
56
+ check_keys = options.key?(:keys)
57
+ check_schema = options.key?(:schema)
58
+
59
+ raise ArgumentError, ':keys or :schema is missing' if !check_keys && !check_schema
60
+ raise ArgumentError, "hash can't be empty" if hash.empty?
61
+
56
62
  require_all = options[:require_all]
57
63
 
58
- return assert_hash_keys!(hash, options[:keys], require_all) if options.key?(:keys)
59
- return assert_hash_schema!(hash, options[:schema], require_all) if options.key?(:schema)
64
+ return assert_hash_keys!(hash, options[:keys], require_all) if check_keys
60
65
 
61
- raise ArgumentError, ':keys or :schema is missing'
66
+ assert_hash_schema!(hash, options[:schema], require_all)
62
67
  end
63
68
 
64
69
  private
@@ -66,7 +71,7 @@ module Kind
66
71
  def assert_hash_keys!(hash, arg, require_all)
67
72
  keys = Array(arg)
68
73
 
69
- ASSERT_HASH_KEYS.require_all(keys, hash) if require_all
74
+ AssertHash::Keys.require_all(keys, hash) if require_all
70
75
 
71
76
  hash.each_key do |k|
72
77
  unless keys.include?(k)
@@ -76,9 +81,9 @@ module Kind
76
81
  end
77
82
 
78
83
  def assert_hash_schema!(hash, schema, require_all)
79
- return ASSERT_HASH_SCHEMA.all(hash, schema) if require_all
84
+ return AssertHash::Schema.all(hash, schema) if require_all
80
85
 
81
- ASSERT_HASH_SCHEMA.any(hash, schema)
86
+ AssertHash::Schema.any(hash, schema)
82
87
  end
83
88
  end
84
89
 
data/lib/kind/any.rb ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kind
4
+ class Any
5
+ FilledList = ->(val) {(val.is_a?(::Array) || val.is_a?(::Set)) && !val.empty?}
6
+
7
+ singleton_class.send(:alias_method, :[], :new)
8
+
9
+ attr_reader :values
10
+
11
+ def initialize(*args)
12
+ array = args.size == 1 ? args[0] : args
13
+
14
+ @values = Kind.of(FilledList, array, expected: 'filled array or set')
15
+ end
16
+
17
+ def ===(value)
18
+ @values.include?(value)
19
+ end
20
+
21
+ def [](value, label: nil)
22
+ STRICT.object_is_a(self, value, label)
23
+ end
24
+
25
+ def |(another_kind)
26
+ UnionType[self] | another_kind
27
+ end
28
+
29
+ def name
30
+ str = @values.inspect
31
+
32
+ if @values.is_a?(::Set)
33
+ str.sub!(/\A#<Set: /, '')
34
+ str.chomp!('>')
35
+ end
36
+
37
+ "Kind::Any#{str}"
38
+ end
39
+
40
+ alias inspect name
41
+
42
+ private_constant :FilledList
43
+ end
44
+ end
data/lib/kind/basic.rb CHANGED
@@ -48,8 +48,8 @@ module Kind
48
48
  KIND.interface?(method_names, value)
49
49
  end
50
50
 
51
- def of(kind, value, label: nil)
52
- STRICT.object_is_a(kind, value, label)
51
+ def of(kind, value, label: nil, expected: nil)
52
+ STRICT.object_is_a(kind, value, label, expected)
53
53
  end
54
54
 
55
55
  alias_method :of!, :of
@@ -33,7 +33,7 @@ module Kind
33
33
  end
34
34
 
35
35
  def key?(arg)
36
- arg.respond_to?(:to_sym) ? ref?(arg) && !value?(arg) : false
36
+ arg.respond_to?(:to_sym) ? ENUM__KEYS.member?(arg.to_s) : false
37
37
  end
38
38
 
39
39
  def value?(arg)
data/lib/kind/enum.rb CHANGED
@@ -11,50 +11,58 @@ module Kind
11
11
  extend self
12
12
 
13
13
  def values(input)
14
- enum_module = ::Module.new
14
+ __create(input)
15
+ end
15
16
 
16
- enum_items =
17
- case input
18
- when ::Hash then create_from_hash(input)
19
- when ::Array then create_from_array(input)
20
- else raise ArgumentError, 'use an array or hash to define a Kind::Enum'
21
- end
17
+ def from_array(input, use_index_as_value:)
18
+ __create(input, use_index_as_value)
19
+ end
22
20
 
23
- enum_items.each { |item| enum_module.const_set(item.name, item) }
21
+ private
24
22
 
25
- enum_map = enum_items.each_with_object({}) do |item, memo|
26
- memo[item.to_s] = item
27
- memo[item.value] = item
28
- memo[item.to_sym] = item
29
- end
23
+ def __create(input, use_index_as_value = true)
24
+ enum_module = ::Module.new
30
25
 
31
- enum_module.const_set(:ENUM__MAP, enum_map)
32
- enum_module.const_set(:ENUM__HASH, enum_items.map(&:to_ary).to_h.freeze)
33
- enum_module.const_set(:ENUM__KEYS, ::Set.new(enum_items.map(&:key)).freeze)
34
- enum_module.const_set(:ENUM__VALS, ::Set.new(enum_items.map(&:value)).freeze)
35
- enum_module.const_set(:ENUM__REFS, ::Set.new(enum_map.keys))
36
- enum_module.const_set(:ENUM__ITEMS, enum_items.freeze)
26
+ enum_items =
27
+ case input
28
+ when ::Hash then __create_from_hash(input)
29
+ when ::Array then __create_from_array(input, use_index_as_value)
30
+ else raise ArgumentError, 'use an array or hash to define a Kind::Enum'
31
+ end
37
32
 
38
- enum_module.send(:private_constant, :ENUM__MAP, :ENUM__HASH, :ENUM__KEYS,
39
- :ENUM__VALS, :ENUM__REFS, :ENUM__ITEMS)
33
+ enum_items.each { |item| enum_module.const_set(item.name, item) }
40
34
 
41
- enum_module.module_eval(METHODS)
35
+ enum_map = enum_items.each_with_object({}) do |item, memo|
36
+ memo[item.to_s] = item
37
+ memo[item.value] = item
38
+ memo[item.to_sym] = item
39
+ end
42
40
 
43
- enum_module.extend(enum_module)
44
- enum_module
45
- end
41
+ enum_module.const_set(:ENUM__MAP, enum_map)
42
+ enum_module.const_set(:ENUM__HASH, enum_items.map(&:to_ary).to_h.freeze)
43
+ enum_module.const_set(:ENUM__KEYS, ::Set.new(enum_items.map(&:key)).freeze)
44
+ enum_module.const_set(:ENUM__VALS, ::Set.new(enum_items.map(&:value)).freeze)
45
+ enum_module.const_set(:ENUM__REFS, ::Set.new(enum_map.keys))
46
+ enum_module.const_set(:ENUM__ITEMS, enum_items.freeze)
46
47
 
47
- private
48
+ enum_module.send(:private_constant, :ENUM__MAP, :ENUM__HASH, :ENUM__KEYS,
49
+ :ENUM__VALS, :ENUM__REFS, :ENUM__ITEMS)
50
+
51
+ enum_module.module_eval(METHODS)
52
+
53
+ enum_module.extend(enum_module)
54
+ enum_module
55
+ end
48
56
 
49
- def create_from_hash(input)
50
- input.map { |key, value| build_item(key, value) }
57
+ def __create_from_hash(input)
58
+ input.map { |key, value| __item(key, value) }
51
59
  end
52
60
 
53
- def create_from_array(input)
54
- input.map.with_index { |key, index| build_item(key, index) }
61
+ def __create_from_array(input, use_index_as_value)
62
+ input.map.with_index { |key, index| use_index_as_value ? __item(key, index) : __item(key, key) }
55
63
  end
56
64
 
57
- def build_item(key, value)
65
+ def __item(key, value)
58
66
  return Item.new(key, value) if key.respond_to?(:to_sym)
59
67
 
60
68
  raise ArgumentError, 'use a string or symbol to define a Kind::Enum item'
@@ -46,6 +46,11 @@ module Kind
46
46
  Object::Instance.new(kind, opt)
47
47
  end
48
48
 
49
+ # Kind.object(name:,&block)
50
+ def self.object(name:, &block)
51
+ self[block, name: name]
52
+ end
53
+
49
54
  # Kind::Of()
50
55
  def self.Of(*args)
51
56
  warn '[DEPRECATION] Kind::Of() is deprecated; use Kind[] instead. ' \
@@ -13,7 +13,7 @@ module Kind
13
13
  :assert_hash!
14
14
  ].each { |method_name| remove_method(method_name) }
15
15
 
16
- def object_is_a(_kind, value, _label = nil) # :nodoc:
16
+ def object_is_a(_kind, value, _label = nil, _expected = nil) # :nodoc:
17
17
  value
18
18
  end
19
19
 
data/lib/kind/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kind
4
- VERSION = '5.7.0'
4
+ VERSION = '5.10.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kind
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.7.0
4
+ version: 5.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Serradura
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-22 00:00:00.000000000 Z
11
+ date: 2021-09-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A development toolkit for Ruby with several small/cohesive abstractions
14
14
  (monads, enums, business logic, data validation...) to empower your development
@@ -19,10 +19,10 @@ executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
+ - ".github/workflows/ci.yml"
22
23
  - ".gitignore"
23
24
  - ".tool-versions"
24
- - ".travis.sh"
25
- - ".travis.yml"
25
+ - ".vscode/settings.json"
26
26
  - CHANGELOG.md
27
27
  - CODE_OF_CONDUCT.md
28
28
  - Gemfile
@@ -30,11 +30,13 @@ files:
30
30
  - README.md
31
31
  - Rakefile
32
32
  - bin/console
33
+ - bin/prepare_coverage
33
34
  - bin/setup
35
+ - bin/test
34
36
  - kind.gemspec
35
37
  - lib/kind.rb
36
38
  - lib/kind/__lib__/action_steps.rb
37
- - lib/kind/__lib__/assert_hash_schema.rb
39
+ - lib/kind/__lib__/assert_hash.rb
38
40
  - lib/kind/__lib__/attributes.rb
39
41
  - lib/kind/__lib__/kind.rb
40
42
  - lib/kind/__lib__/of.rb
@@ -42,6 +44,7 @@ files:
42
44
  - lib/kind/__lib__/undefined.rb
43
45
  - lib/kind/action.rb
44
46
  - lib/kind/active_model/validation.rb
47
+ - lib/kind/any.rb
45
48
  - lib/kind/basic.rb
46
49
  - lib/kind/basic/error.rb
47
50
  - lib/kind/basic/undefined.rb
@@ -120,14 +123,13 @@ files:
120
123
  - lib/kind/try.rb
121
124
  - lib/kind/validator.rb
122
125
  - lib/kind/version.rb
123
- - test.sh
124
126
  homepage: https://github.com/serradura/kind
125
127
  licenses:
126
128
  - MIT
127
129
  metadata:
128
130
  homepage_uri: https://github.com/serradura/kind
129
131
  source_code_uri: https://github.com/serradura/kind
130
- post_install_message:
132
+ post_install_message:
131
133
  rdoc_options: []
132
134
  require_paths:
133
135
  - lib
@@ -143,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
145
  version: '0'
144
146
  requirements: []
145
147
  rubygems_version: 3.2.11
146
- signing_key:
148
+ signing_key:
147
149
  specification_version: 4
148
150
  summary: A development toolkit for Ruby with several small/cohesive abstractions to
149
151
  empower your development workflow.
data/.travis.sh DELETED
@@ -1,77 +0,0 @@
1
- #!/bin/bash
2
-
3
- RUBY_V=$(ruby -v)
4
-
5
- function run_basic_tests {
6
- if [ ! -z "$1" ]; then
7
- bundle_cmd="bundle _$1_"
8
- else
9
- bundle_cmd="bundle"
10
- fi
11
-
12
- eval "KIND_BASIC=t $bundle_cmd exec rake test TEST='test/kind/{basic/*_test,basic_test}.rb'"
13
- eval "KIND_BASIC=t $bundle_cmd exec rake test TEST='test/kind/enum_test.rb'"
14
- eval "KIND_BASIC=t $bundle_cmd exec rake test TEST='test/kind/presence_test.rb'"
15
- eval "KIND_BASIC=t $bundle_cmd exec rake test TEST='test/kind/dig_test.rb'"
16
- eval "KIND_BASIC=t $bundle_cmd exec rake test TEST='test/kind/try_test.rb'"
17
- eval "KIND_BASIC=t $bundle_cmd exec rake test TEST='test/kind/maybe_test.rb'"
18
- eval "KIND_BASIC=t $bundle_cmd exec rake test TEST='test/kind/immutable_attributes_test.rb'"
19
- eval "KIND_BASIC=t $bundle_cmd exec rake test TEST='test/kind/function_test.rb'"
20
- eval "KIND_BASIC=t $bundle_cmd exec rake test TEST='test/kind/action_test.rb'"
21
- eval "KIND_BASIC=t $bundle_cmd exec rake test TEST='test/kind/{functional/*_test,functional_test}.rb'"
22
- eval "KIND_BASIC=t $bundle_cmd exec rake test TEST='test/kind/either/*_test.rb'"
23
- eval "KIND_BASIC=t $bundle_cmd exec rake test TEST='test/kind/result/*_test.rb'"
24
-
25
- eval "KIND_STRICT=t $bundle_cmd exec rake test TEST='test/kind/strict_disabled_test.rb'"
26
- }
27
-
28
- function run_with_bundler {
29
- rm Gemfile.lock
30
-
31
- if [ ! -z "$1" ]; then
32
- bundle_cmd="bundle _$1_"
33
- else
34
- bundle_cmd="bundle"
35
- fi
36
-
37
- eval "$2 $bundle_cmd update"
38
- eval "$2 $bundle_cmd exec rake test"
39
- }
40
-
41
- function run_with_am_version_and_bundler {
42
- run_with_bundler "$2" "ACTIVEMODEL_VERSION=$1"
43
- }
44
-
45
- RUBY_2_12="ruby 2.[12]."
46
- RUBY_2_2345="ruby 2.[2345]."
47
- RUBY_2_12345="ruby 2.[12345]."
48
- RUBY_2_567="ruby 2.[567]."
49
- RUBY_3_0="ruby 3.0."
50
-
51
- if [[ $RUBY_V =~ $RUBY_2_12 ]]; then
52
- run_with_am_version_and_bundler "3.2" "$BUNDLER_V1"
53
- fi
54
-
55
- if [[ $RUBY_V =~ $RUBY_2_2345 ]]; then
56
- run_with_am_version_and_bundler "4.0" "$BUNDLER_V1"
57
- run_with_am_version_and_bundler "4.1" "$BUNDLER_V1"
58
- run_with_am_version_and_bundler "4.2" "$BUNDLER_V1"
59
- run_with_am_version_and_bundler "5.0" "$BUNDLER_V1"
60
- run_with_am_version_and_bundler "5.1" "$BUNDLER_V1"
61
- run_with_am_version_and_bundler "5.2" "$BUNDLER_V1"
62
- fi
63
-
64
- if [[ $RUBY_V =~ $RUBY_2_12345 ]]; then
65
- run_basic_tests "$BUNDLER_V1"
66
- run_with_bundler "$BUNDLER_V1"
67
- fi
68
-
69
- if [[ $RUBY_V =~ $RUBY_2_567 ]] || [[ $RUBY_V =~ $RUBY_3_0 ]]; then
70
- gem install bundler -v ">= 2" --no-doc
71
-
72
- run_with_am_version_and_bundler "6.0"
73
- run_with_am_version_and_bundler "6.1"
74
-
75
- run_basic_tests
76
- run_with_bundler
77
- fi
data/.travis.yml DELETED
@@ -1,35 +0,0 @@
1
- ---
2
- language: ruby
3
-
4
- cache:
5
- bundler: true
6
- directories:
7
- - /home/travis/.rvm/
8
-
9
- rvm:
10
- - 2.1.10
11
- - 2.2.2
12
- - 2.3.0
13
- - 2.4.0
14
- - 2.5.0
15
- - 2.6.0
16
- - 2.7.0
17
- - 3.0.0
18
-
19
- env:
20
- - BUNDLER_V1="1.17.3"
21
-
22
- before_install:
23
- - gem install bundler -v "$BUNDLER_V1"
24
-
25
- install: bundle install --jobs=3 --retry=3
26
-
27
- before_script:
28
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
29
- - chmod +x ./cc-test-reporter
30
- - "./cc-test-reporter before-build"
31
-
32
- script: "./.travis.sh"
33
-
34
- after_success:
35
- - "./cc-test-reporter after-build -t simplecov"
@@ -1,81 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Kind
4
- module ASSERT_HASH_KEYS
5
- def self.require_all(keys, hash)
6
- expected_keys = keys - hash.keys
7
-
8
- unless expected_keys.empty?
9
- raise KeyError.new("#{hash.inspect} expected to have these keys: #{expected_keys}")
10
- end
11
-
12
- unexpected_keys = hash.keys - keys
13
-
14
- unless unexpected_keys.empty?
15
- raise KeyError.new("#{hash.inspect} expected to NOT have these keys: #{unexpected_keys}")
16
- end
17
-
18
- hash
19
- end
20
- end
21
-
22
- module ASSERT_HASH_SCHEMA
23
- extend self
24
-
25
- UnionType = ->(value) do
26
- defined?(Kind::UnionType) ? Kind::UnionType === value : false
27
- end
28
-
29
- def any(hash, spec)
30
- spec.each do |key, expected|
31
- value = hash[key]
32
- error_message = "The key #{key.inspect} has an invalid value"
33
-
34
- case expected
35
- when ::Module then assert_kind_of(expected, value, error_message)
36
- when ::Proc then assert(expected.call(value), error_message)
37
- when ::Regexp then assert_match(expected, value, error_message)
38
- when ::NilClass then assert_nil(value, error_message)
39
- when UnionType then assert(expected === value, error_message)
40
- else assert_equal(expected, value, error_message)
41
- end
42
- end
43
-
44
- hash
45
- end
46
-
47
- def all(hash, spec)
48
- ASSERT_HASH_KEYS.require_all(spec.keys, hash)
49
-
50
- any(hash, spec)
51
- end
52
-
53
- private
54
-
55
- def assert_equal(expected, value, message)
56
- raise_kind_error(message) if expected != value
57
- end
58
-
59
- def assert(value, message)
60
- raise_kind_error(message) unless value
61
- end
62
-
63
- def assert_nil(value, message)
64
- raise_kind_error(message) unless value.nil?
65
- end
66
-
67
- def assert_match(expected, value, message)
68
- STRICT.kind_of(String, value)
69
-
70
- raise_kind_error(message) if value !~ expected
71
- end
72
-
73
- def assert_kind_of(expected, value, message)
74
- raise_kind_error(message) unless expected === value
75
- end
76
-
77
- def raise_kind_error(message)
78
- raise Error.new(message)
79
- end
80
- end
81
- end
data/test.sh DELETED
@@ -1,11 +0,0 @@
1
- #!/bin/bash
2
-
3
- source $(dirname $0)/.travis.sh
4
-
5
- echo ''
6
- echo 'Resetting Gemfile'
7
- echo ''
8
-
9
- rm Gemfile.lock
10
-
11
- bundle