kind 5.8.1 → 5.9.0

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
2
  SHA256:
3
- metadata.gz: 9f597d5c2bf74605429011719cb548759b2acb223a0947f4d26137ad02ade075
4
- data.tar.gz: 66e68c83721e37746d3102bed5befe2e7e0d3c30fd2e0ff02bc30007114620dc
3
+ metadata.gz: 195bae736a96e62b9320b209bc7845d6e8c39714342ccb34dfe5bf1ea7c169d8
4
+ data.tar.gz: 2cbf9ba591a62456ff1faf3f8e8e8b1052b9f2c61d96a9a8df62b7ba595a5ac4
5
5
  SHA512:
6
- metadata.gz: 856b289e62376c59e570c1de277e976e9434040dedd12cbaaca7ef8a71aa1c33ba1d2c304a3c5b7634830326838ac58ace2c5647d8c5b36a9df1638c70e67385
7
- data.tar.gz: 831252cae86eee16ae082a9f64f5065ed2dfcb33ae2df904517cce929b81a7951fd844f895fce1a44b30d60901e36f4642c74dbd9b861d9de76b9ef72146acc4
6
+ metadata.gz: 37e37d949dda2c0bbe11642742473200ff42d4300d63642819532fd32beec8485c953588ad100b2c771ec0e8528281d5535180aa21ceb1e53dfe45f992ad7141
7
+ data.tar.gz: 93e92d5db75442cb9c637924d731eec70f7324d50f9c2da91100b1bc916ef8a8ab8c7ea1bbf7590107141a1fc9e81181f51bc5c2848500f0ed7bc940adbaa36f
data/CHANGELOG.md CHANGED
@@ -3,89 +3,91 @@
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.9.0 (2021-09-22)](#590-2021-09-22)
7
+ - [Added](#added)
6
8
  - [5.8.1 (2021-09-22)](#581-2021-09-22)
7
9
  - [Fixed](#fixed)
8
10
  - [5.8.0 (2021-09-22)](#580-2021-09-22)
9
- - [Added](#added)
10
- - [5.7.0 (2021-06-22)](#570-2021-06-22)
11
11
  - [Added](#added-1)
12
- - [5.6.0 (2021-05-14)](#560-2021-05-14)
12
+ - [5.7.0 (2021-06-22)](#570-2021-06-22)
13
13
  - [Added](#added-2)
14
- - [5.5.0 (2021-04-05)](#550-2021-04-05)
14
+ - [5.6.0 (2021-05-14)](#560-2021-05-14)
15
15
  - [Added](#added-3)
16
+ - [5.5.0 (2021-04-05)](#550-2021-04-05)
17
+ - [Added](#added-4)
16
18
  - [5.4.1 (2021-03-26)](#541-2021-03-26)
17
19
  - [Fixed](#fixed-1)
18
20
  - [5.4.0 (2021-03-25)](#540-2021-03-25)
19
- - [Added](#added-4)
20
- - [5.3.0 (2021-03-23)](#530-2021-03-23)
21
21
  - [Added](#added-5)
22
- - [5.2.0 (2021-03-17)](#520-2021-03-17)
22
+ - [5.3.0 (2021-03-23)](#530-2021-03-23)
23
23
  - [Added](#added-6)
24
+ - [5.2.0 (2021-03-17)](#520-2021-03-17)
25
+ - [Added](#added-7)
24
26
  - [Deprecated](#deprecated)
25
27
  - [Changes](#changes)
26
28
  - [5.1.0 (2021-02-23)](#510-2021-02-23)
27
- - [Added](#added-7)
29
+ - [Added](#added-8)
28
30
  - [Deprecated](#deprecated-1)
29
31
  - [5.0.0 (2021-02-22)](#500-2021-02-22)
30
32
  - [Breaking Changes](#breaking-changes)
31
33
  - [Removed](#removed)
32
34
  - [4.1.0 (2021-02-22)](#410-2021-02-22)
33
- - [Added](#added-8)
34
- - [4.0.0 (2021-02-22)](#400-2021-02-22)
35
35
  - [Added](#added-9)
36
+ - [4.0.0 (2021-02-22)](#400-2021-02-22)
37
+ - [Added](#added-10)
36
38
  - [Deprecated](#deprecated-2)
37
39
  - [Fixed](#fixed-2)
38
40
  - [3.1.0 (2020-07-08)](#310-2020-07-08)
39
- - [Added](#added-10)
41
+ - [Added](#added-11)
40
42
  - [3.0.0 (2020-06-25)](#300-2020-06-25)
41
43
  - [Breaking Changes](#breaking-changes-1)
42
- - [Added](#added-11)
43
- - [2.3.0 (2020-06-24)](#230-2020-06-24)
44
44
  - [Added](#added-12)
45
- - [2.2.0 (2020-06-23)](#220-2020-06-23)
45
+ - [2.3.0 (2020-06-24)](#230-2020-06-24)
46
46
  - [Added](#added-13)
47
- - [2.1.0 (2020-05-12)](#210-2020-05-12)
47
+ - [2.2.0 (2020-06-23)](#220-2020-06-23)
48
48
  - [Added](#added-14)
49
+ - [2.1.0 (2020-05-12)](#210-2020-05-12)
50
+ - [Added](#added-15)
49
51
  - [Breaking Changes](#breaking-changes-2)
50
52
  - [2.0.0 (2020-05-07)](#200-2020-05-07)
51
- - [Added](#added-15)
53
+ - [Added](#added-16)
52
54
  - [Breaking Changes](#breaking-changes-3)
53
55
  - [Removed](#removed-1)
54
56
  - [1.9.0 (2020-05-06)](#190-2020-05-06)
55
- - [Added](#added-16)
56
- - [1.8.0 (2020-05-03)](#180-2020-05-03)
57
57
  - [Added](#added-17)
58
+ - [1.8.0 (2020-05-03)](#180-2020-05-03)
59
+ - [Added](#added-18)
58
60
  - [1.7.0 (2020-05-03)](#170-2020-05-03)
59
61
  - [Fixed](#fixed-3)
60
62
  - [1.6.0 (2020-04-17)](#160-2020-04-17)
61
- - [Added](#added-18)
63
+ - [Added](#added-19)
62
64
  - [Changes](#changes-1)
63
65
  - [1.5.0 (2020-04-12)](#150-2020-04-12)
64
- - [Added](#added-19)
65
- - [1.4.0 (2020-04-12)](#140-2020-04-12)
66
66
  - [Added](#added-20)
67
- - [1.3.0 (2020-04-12)](#130-2020-04-12)
67
+ - [1.4.0 (2020-04-12)](#140-2020-04-12)
68
68
  - [Added](#added-21)
69
- - [1.2.0 (2020-04-12)](#120-2020-04-12)
69
+ - [1.3.0 (2020-04-12)](#130-2020-04-12)
70
70
  - [Added](#added-22)
71
- - [1.1.0 (2020-04-09)](#110-2020-04-09)
71
+ - [1.2.0 (2020-04-12)](#120-2020-04-12)
72
72
  - [Added](#added-23)
73
+ - [1.1.0 (2020-04-09)](#110-2020-04-09)
74
+ - [Added](#added-24)
73
75
  - [Fixed](#fixed-4)
74
76
  - [1.0.0 (2020-03-16)](#100-2020-03-16)
75
- - [Added](#added-24)
76
- - [0.6.0 (2020-01-06)](#060-2020-01-06)
77
77
  - [Added](#added-25)
78
- - [0.5.0 (2020-01-04)](#050-2020-01-04)
78
+ - [0.6.0 (2020-01-06)](#060-2020-01-06)
79
79
  - [Added](#added-26)
80
- - [0.4.0 (2020-01-03)](#040-2020-01-03)
80
+ - [0.5.0 (2020-01-04)](#050-2020-01-04)
81
81
  - [Added](#added-27)
82
- - [0.3.0 (2020-01-03)](#030-2020-01-03)
82
+ - [0.4.0 (2020-01-03)](#040-2020-01-03)
83
83
  - [Added](#added-28)
84
+ - [0.3.0 (2020-01-03)](#030-2020-01-03)
85
+ - [Added](#added-29)
84
86
  - [Breaking Changes](#breaking-changes-4)
85
87
  - [0.2.0 (2020-01-02)](#020-2020-01-02)
86
- - [Added](#added-29)
87
- - [0.1.0 (2019-12-26)](#010-2019-12-26)
88
88
  - [Added](#added-30)
89
+ - [0.1.0 (2019-12-26)](#010-2019-12-26)
90
+ - [Added](#added-31)
89
91
 
90
92
  ## Unreleased
91
93
 
@@ -97,6 +99,80 @@ This project follows [semver 2.0.0](http://semver.org/spec/v2.0.0.html) and the
97
99
  ### Fixed
98
100
  -->
99
101
 
102
+ 5.9.0 (2021-09-22)
103
+ ------------------
104
+
105
+ ### Added
106
+
107
+ * [#68](https://github.com/serradura/kind/pull/68) - Add `Kind.object(name:, &block)` to create `Kind::Objects`.
108
+ ```ruby
109
+ PositiveInteger = Kind.object(name: 'PositiveInteger') do |value|
110
+ value.kind_of?(Integer) && value > 0
111
+ end
112
+
113
+ # PositiveInteger.name
114
+ # PositiveInteger.kind
115
+ # The type handler can return its kind and its name
116
+ PositiveInteger.name # "PositiveInteger"
117
+ PositiveInteger.kind # #<Proc:0x0000.... >
118
+
119
+ # PositiveInteger.===
120
+ # Can check if a given value is an instance of its kind.
121
+ PositiveInteger === 1 # true
122
+ PositiveInteger === 0 # false
123
+
124
+ # PositiveInteger.value?(value)
125
+ # Can check if a given value is an instance of its kind.
126
+ PositiveInteger.value?(1) # true
127
+ PositiveInteger.value?(-1) # false
128
+
129
+ # If it doesn't receive an argument, a lambda will be returned and it will know how to do the type verification.
130
+ [1, 2, 0, 3, -1].select(&PositiveInteger.value?) # [1, 2, 3]
131
+
132
+ # PositiveInteger.or_nil(value)
133
+ # Can return nil if the given value isn't an instance of its kind
134
+ PositiveInteger.or_nil(1) # 1
135
+ PositiveInteger.or_nil(0) # nil
136
+
137
+ # PositiveInteger.or_undefined(value)
138
+ # Can return Kind::Undefined if the given value isn't an instance of its kind
139
+ PositiveInteger.or_undefined(2) # 2
140
+ PositiveInteger.or_undefined(-1) # Kind::Undefined
141
+
142
+ # PositiveInteger.or(fallback, value)
143
+ # Can return a fallback if the given value isn't an instance of its kind
144
+ PositiveInteger.or(nil, 1) # 1
145
+ PositiveInteger.or(nil, 0) # nil
146
+
147
+ # 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.
148
+ [1, 2, 0, 3, -1].map(&PositiveInteger.or(1)) # [1, 2, 1, 3, 1]
149
+ [1, 2, 0, 3, -1].map(&PositiveInteger.or(nil)) # [1, 2, nil, 3, nil]
150
+
151
+ # An error will be raised if the fallback didn't have the expected kind or if not nil / Kind::Undefined.
152
+ [1, 2, 0, 3, -1].map(&PositiveInteger.or(:foo)) # Kind::Error (:foo expected to be a kind of PositiveInteger)
153
+
154
+ # PositiveInteger[value]
155
+ # Will raise Kind::Error if the given value isn't an instance of the expected kind
156
+ PositiveInteger[1] # 1
157
+ PositiveInteger[:foo] # Kind::Error (:foo expected to be a kind of PositiveInteger)
158
+
159
+ # PositiveInteger.value(arg, default:)
160
+ # 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.
161
+ PositiveInteger.value(2, default: 1) # 2
162
+
163
+ PositiveInteger.value('1', default: 1) # 1
164
+
165
+ PositiveInteger.value('1', default: 0) # Kind::Error (0 expected to be a kind of PositiveInteger)
166
+
167
+ # PositiveInteger.maybe
168
+ # This method returns a typed Kind::Maybe.
169
+ PositiveInteger.maybe(0).value_or(1) # 1
170
+
171
+ PositiveInteger.maybe(2).value_or(1) # 2
172
+ ```
173
+
174
+ [⬆️ &nbsp;Back to Top](#changelog-)
175
+
100
176
  5.8.1 (2021-09-22)
101
177
  ------------------
102
178
 
@@ -169,7 +245,7 @@ Kind.assert_hash!({level: :medium}, schema: {level: Level})
169
245
  FilledString = begin
170
246
  filled_string = ->(value) {value.is_a?(String) && value.present?}
171
247
 
172
- Kind::Of(filled_string, name: 'FilledString')
248
+ Kind[filled_string, name: 'FilledString']
173
249
  end
174
250
 
175
251
  Kind.assert_hash!(some_hash, schema: {
data/README.md CHANGED
@@ -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.8.1 | https://github.com/serradura/kind/blob/v5.x/README.md
45
+ 5.9.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.8.1 | v5.x | >= 2.1.0, <= 3.0.0 | >= 3.2, < 7.0 |
128
+ | 5.9.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
@@ -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. ' \
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.8.1'
4
+ VERSION = '5.9.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kind
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.8.1
4
+ version: 5.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Serradura