domainic-type 0.1.0.alpha.2.1.0 → 0.1.0.alpha.3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/LICENSE +1 -1
- data/README.md +28 -4
- data/lib/domainic/type/accessors.rb +41 -0
- data/lib/domainic/type/behavior/enumerable_behavior.rb +262 -0
- data/lib/domainic/type/behavior/numeric_behavior.rb +340 -0
- data/lib/domainic/type/behavior/sizable_behavior.rb +246 -0
- data/lib/domainic/type/behavior/string_behavior.rb +379 -0
- data/lib/domainic/type/behavior.rb +239 -0
- data/lib/domainic/type/config/registry.yml +101 -0
- data/lib/domainic/type/constraint/behavior.rb +342 -0
- data/lib/domainic/type/constraint/constraints/all_constraint.rb +81 -0
- data/lib/domainic/type/constraint/constraints/and_constraint.rb +105 -0
- data/lib/domainic/type/constraint/constraints/any_constraint.rb +83 -0
- data/lib/domainic/type/constraint/constraints/case_constraint.rb +104 -0
- data/lib/domainic/type/constraint/constraints/character_set_constraint.rb +111 -0
- data/lib/domainic/type/constraint/constraints/divisibility_constraint.rb +126 -0
- data/lib/domainic/type/constraint/constraints/emptiness_constraint.rb +69 -0
- data/lib/domainic/type/constraint/constraints/equality_constraint.rb +75 -0
- data/lib/domainic/type/constraint/constraints/finiteness_constraint.rb +123 -0
- data/lib/domainic/type/constraint/constraints/inclusion_constraint.rb +74 -0
- data/lib/domainic/type/constraint/constraints/match_pattern_constraint.rb +87 -0
- data/lib/domainic/type/constraint/constraints/method_presence_constraint.rb +72 -0
- data/lib/domainic/type/constraint/constraints/none_constraint.rb +83 -0
- data/lib/domainic/type/constraint/constraints/nor_constraint.rb +105 -0
- data/lib/domainic/type/constraint/constraints/not_constraint.rb +76 -0
- data/lib/domainic/type/constraint/constraints/or_constraint.rb +106 -0
- data/lib/domainic/type/constraint/constraints/ordering_constraint.rb +75 -0
- data/lib/domainic/type/constraint/constraints/parity_constraint.rb +102 -0
- data/lib/domainic/type/constraint/constraints/polarity_constraint.rb +147 -0
- data/lib/domainic/type/constraint/constraints/range_constraint.rb +135 -0
- data/lib/domainic/type/constraint/constraints/type_constraint.rb +110 -0
- data/lib/domainic/type/constraint/constraints/uniqueness_constraint.rb +69 -0
- data/lib/domainic/type/constraint/resolver.rb +172 -0
- data/lib/domainic/type/constraint/set.rb +266 -0
- data/lib/domainic/type/definitions.rb +364 -0
- data/lib/domainic/type/types/core/array_type.rb +48 -0
- data/lib/domainic/type/types/core/float_type.rb +39 -0
- data/lib/domainic/type/types/core/hash_type.rb +143 -0
- data/lib/domainic/type/types/core/integer_type.rb +38 -0
- data/lib/domainic/type/types/core/string_type.rb +51 -0
- data/lib/domainic/type/types/core/symbol_type.rb +51 -0
- data/lib/domainic/type/types/specification/anything_type.rb +22 -0
- data/lib/domainic/type/types/specification/duck_type.rb +55 -0
- data/lib/domainic/type/types/specification/enum_type.rb +26 -0
- data/lib/domainic/type/types/specification/union_type.rb +26 -0
- data/lib/domainic/type/types/specification/void_type.rb +12 -0
- data/lib/domainic/type.rb +7 -0
- data/lib/domainic-type.rb +3 -0
- data/sig/domainic/type/accessors.rbs +22 -0
- data/sig/domainic/type/behavior/enumerable_behavior.rbs +238 -0
- data/sig/domainic/type/behavior/numeric_behavior.rbs +299 -0
- data/sig/domainic/type/behavior/sizable_behavior.rbs +218 -0
- data/sig/domainic/type/behavior/string_behavior.rbs +315 -0
- data/sig/domainic/type/behavior.rbs +153 -0
- data/sig/domainic/type/constraint/behavior.rbs +258 -0
- data/sig/domainic/type/constraint/constraints/all_constraint.rbs +55 -0
- data/sig/domainic/type/constraint/constraints/and_constraint.rbs +72 -0
- data/sig/domainic/type/constraint/constraints/any_constraint.rbs +57 -0
- data/sig/domainic/type/constraint/constraints/case_constraint.rbs +73 -0
- data/sig/domainic/type/constraint/constraints/character_set_constraint.rbs +82 -0
- data/sig/domainic/type/constraint/constraints/divisibility_constraint.rbs +91 -0
- data/sig/domainic/type/constraint/constraints/emptiness_constraint.rbs +54 -0
- data/sig/domainic/type/constraint/constraints/equality_constraint.rbs +60 -0
- data/sig/domainic/type/constraint/constraints/finiteness_constraint.rbs +82 -0
- data/sig/domainic/type/constraint/constraints/inclusion_constraint.rbs +59 -0
- data/sig/domainic/type/constraint/constraints/match_pattern_constraint.rbs +66 -0
- data/sig/domainic/type/constraint/constraints/method_presence_constraint.rbs +51 -0
- data/sig/domainic/type/constraint/constraints/none_constraint.rbs +57 -0
- data/sig/domainic/type/constraint/constraints/nor_constraint.rbs +72 -0
- data/sig/domainic/type/constraint/constraints/not_constraint.rbs +56 -0
- data/sig/domainic/type/constraint/constraints/or_constraint.rbs +74 -0
- data/sig/domainic/type/constraint/constraints/ordering_constraint.rbs +60 -0
- data/sig/domainic/type/constraint/constraints/parity_constraint.rbs +71 -0
- data/sig/domainic/type/constraint/constraints/polarity_constraint.rbs +101 -0
- data/sig/domainic/type/constraint/constraints/range_constraint.rbs +88 -0
- data/sig/domainic/type/constraint/constraints/type_constraint.rbs +86 -0
- data/sig/domainic/type/constraint/constraints/uniqueness_constraint.rbs +54 -0
- data/sig/domainic/type/constraint/resolver.rbs +117 -0
- data/sig/domainic/type/constraint/set.rbs +159 -0
- data/sig/domainic/type/definitions.rbs +304 -0
- data/sig/domainic/type/types/core/array_type.rbs +42 -0
- data/sig/domainic/type/types/core/float_type.rbs +33 -0
- data/sig/domainic/type/types/core/hash_type.rbs +107 -0
- data/sig/domainic/type/types/core/integer_type.rbs +32 -0
- data/sig/domainic/type/types/core/string_type.rbs +45 -0
- data/sig/domainic/type/types/core/symbol_type.rbs +45 -0
- data/sig/domainic/type/types/specification/anything_type.rbs +14 -0
- data/sig/domainic/type/types/specification/duck_type.rbs +41 -0
- data/sig/domainic/type/types/specification/enum_type.rbs +14 -0
- data/sig/domainic/type/types/specification/union_type.rbs +14 -0
- data/sig/domainic/type/types/specification/void_type.rbs +8 -0
- data/sig/domainic/type.rbs +5 -0
- data/sig/domainic-type.rbs +1 -0
- data/sig/manifest.yaml +2 -0
- metadata +108 -71
@@ -0,0 +1,299 @@
|
|
1
|
+
module Domainic
|
2
|
+
module Type
|
3
|
+
module Behavior
|
4
|
+
# A module providing numeric-specific validation behaviors for types.
|
5
|
+
#
|
6
|
+
# This module extends the base Type::Behavior with methods specifically designed for validating numeric values.
|
7
|
+
# It provides a fluent interface for common numeric validations such as divisibility, equality, parity, polarity,
|
8
|
+
# and range constraints. These methods support a variety of constraints and chaining for flexibility in validation
|
9
|
+
# logic.
|
10
|
+
#
|
11
|
+
# @example Basic usage
|
12
|
+
# class NumericType
|
13
|
+
# include Domainic::Type::Behavior::NumericBehavior
|
14
|
+
#
|
15
|
+
# def initialize
|
16
|
+
# super
|
17
|
+
# being_positive # validates that the value is positive
|
18
|
+
# being_divisible_by(5) # validates that the value is divisible by 5
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# @example Combining constraints
|
23
|
+
# class AdvancedNumericType
|
24
|
+
# include Domainic::Type::Behavior::NumericBehavior
|
25
|
+
#
|
26
|
+
# def initialize
|
27
|
+
# super
|
28
|
+
# being_finite
|
29
|
+
# being_greater_than_or_equal_to(0)
|
30
|
+
# being_less_than(100)
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
35
|
+
# @since 0.1.0
|
36
|
+
module NumericBehavior
|
37
|
+
# Constrain the numeric value to be divisible by a given divisor.
|
38
|
+
#
|
39
|
+
# @example
|
40
|
+
# type.being_divisible_by(3)
|
41
|
+
# type.validate(9) # => true
|
42
|
+
# type.validate(10) # => false
|
43
|
+
#
|
44
|
+
# @note the divisor MUST be provided as an argument or in the options Hash.
|
45
|
+
#
|
46
|
+
# @param arguments [Array<Numeric>] a list of arguments, typically one divisor
|
47
|
+
# @param options [Hash] additional options such as tolerance for floating-point checks
|
48
|
+
# @option options [Numeric] :divisor the divisor to check for divisibility
|
49
|
+
# @option options [Numeric] :tolerance the tolerance for floating-point checks
|
50
|
+
#
|
51
|
+
# @return [self] the current instance for chaining
|
52
|
+
def being_divisible_by: (*Numeric arguments, ?divisor: Numeric, ?tolerance: Numeric) -> Behavior
|
53
|
+
|
54
|
+
alias being_multiple_of being_divisible_by
|
55
|
+
|
56
|
+
alias divisible_by being_divisible_by
|
57
|
+
|
58
|
+
alias multiple_of being_divisible_by
|
59
|
+
|
60
|
+
# Constrain the numeric value to equal a specific number.
|
61
|
+
#
|
62
|
+
# @example
|
63
|
+
# type.being_equal_to(42)
|
64
|
+
# type.validate(42) # => true
|
65
|
+
# type.validate(7) # => false
|
66
|
+
#
|
67
|
+
# @param numeric [Numeric] the number to constrain equality to
|
68
|
+
#
|
69
|
+
# @return [self] the current instance for chaining
|
70
|
+
def being_equal_to: (Numeric numeric) -> Behavior
|
71
|
+
|
72
|
+
alias eql being_equal_to
|
73
|
+
|
74
|
+
alias equal_to being_equal_to
|
75
|
+
|
76
|
+
alias equaling being_equal_to
|
77
|
+
|
78
|
+
# Constrain the numeric value to be even.
|
79
|
+
#
|
80
|
+
# @example
|
81
|
+
# type.being_even
|
82
|
+
# type.validate(4) # => true
|
83
|
+
# type.validate(3) # => false
|
84
|
+
#
|
85
|
+
# @return [self] the current instance for chaining
|
86
|
+
def being_even: () -> Behavior
|
87
|
+
|
88
|
+
alias even being_even
|
89
|
+
|
90
|
+
alias not_being_odd being_even
|
91
|
+
|
92
|
+
# Constrain the numeric value to be finite.
|
93
|
+
#
|
94
|
+
# @example
|
95
|
+
# type.being_finite
|
96
|
+
# type.validate(42) # => true
|
97
|
+
# type.validate(Float::INFINITY) # => false
|
98
|
+
#
|
99
|
+
# @return [self] the current instance for chaining
|
100
|
+
def being_finite: () -> Behavior
|
101
|
+
|
102
|
+
alias finite being_finite
|
103
|
+
|
104
|
+
alias not_being_infinite being_finite
|
105
|
+
|
106
|
+
# Constrain the numeric value to be greater than a specific number.
|
107
|
+
#
|
108
|
+
# @example
|
109
|
+
# type.being_greater_than(5)
|
110
|
+
# type.validate(10) # => true
|
111
|
+
# type.validate(3) # => false
|
112
|
+
#
|
113
|
+
# @param numeric [Numeric] the minimum value (exclusive)
|
114
|
+
#
|
115
|
+
# @return [self] the current instance for chaining
|
116
|
+
def being_greater_than: (Numeric numeric) -> Behavior
|
117
|
+
|
118
|
+
alias gt being_greater_than
|
119
|
+
|
120
|
+
alias greater_than being_greater_than
|
121
|
+
|
122
|
+
# Constrain the numeric value to be greater than or equal to a specific number.
|
123
|
+
#
|
124
|
+
# @example
|
125
|
+
# type.being_greater_than_or_equal_to(5)
|
126
|
+
# type.validate(5) # => true
|
127
|
+
# type.validate(3) # => false
|
128
|
+
#
|
129
|
+
# @param numeric [Numeric] the minimum value (inclusive)
|
130
|
+
#
|
131
|
+
# @return [self] the current instance for chaining
|
132
|
+
def being_greater_than_or_equal_to: (Numeric numeric) -> Behavior
|
133
|
+
|
134
|
+
alias gte being_greater_than_or_equal_to
|
135
|
+
|
136
|
+
alias gteq being_greater_than_or_equal_to
|
137
|
+
|
138
|
+
alias greater_than_or_equal_to being_greater_than_or_equal_to
|
139
|
+
|
140
|
+
# Constrain the numeric value to be infinite.
|
141
|
+
#
|
142
|
+
# @example
|
143
|
+
# type.being_infinite
|
144
|
+
# type.validate(Float::INFINITY) # => true
|
145
|
+
# type.validate(42) # => false
|
146
|
+
#
|
147
|
+
# @return [self] the current instance for chaining
|
148
|
+
def being_infinite: () -> Behavior
|
149
|
+
|
150
|
+
alias infinite being_infinite
|
151
|
+
|
152
|
+
alias not_being_finite being_infinite
|
153
|
+
|
154
|
+
# Constrain the numeric value to be less than a specific number.
|
155
|
+
#
|
156
|
+
# @example
|
157
|
+
# type.being_less_than(10)
|
158
|
+
# type.validate(5) # => true
|
159
|
+
# type.validate(10) # => false
|
160
|
+
#
|
161
|
+
# @param numeric [Numeric] the maximum value (exclusive)
|
162
|
+
#
|
163
|
+
# @return [self] the current instance for chaining
|
164
|
+
def being_less_than: (Numeric numeric) -> Behavior
|
165
|
+
|
166
|
+
alias lt being_less_than
|
167
|
+
|
168
|
+
alias less_than being_less_than
|
169
|
+
|
170
|
+
# Constrain the numeric value to be less than or equal to a specific number.
|
171
|
+
#
|
172
|
+
# @example
|
173
|
+
# type.being_less_than_or_equal_to(10)
|
174
|
+
# type.validate(5) # => true
|
175
|
+
# type.validate(15) # => false
|
176
|
+
#
|
177
|
+
# @param numeric [Numeric] the maximum value (inclusive)
|
178
|
+
#
|
179
|
+
# @return [self] the current instance for chaining
|
180
|
+
def being_less_than_or_equal_to: (Numeric numeric) -> Behavior
|
181
|
+
|
182
|
+
alias lte being_less_than_or_equal_to
|
183
|
+
|
184
|
+
alias lteq being_less_than_or_equal_to
|
185
|
+
|
186
|
+
alias less_than_or_equal_to being_less_than_or_equal_to
|
187
|
+
|
188
|
+
# Constrain the numeric value to be negative.
|
189
|
+
#
|
190
|
+
# @example
|
191
|
+
# type.being_negative
|
192
|
+
# type.validate(-5) # => true
|
193
|
+
# type.validate(5) # => false
|
194
|
+
#
|
195
|
+
# @return [self] the current instance for chaining
|
196
|
+
def being_negative: () -> Behavior
|
197
|
+
|
198
|
+
alias negative being_negative
|
199
|
+
|
200
|
+
alias not_being_positive being_negative
|
201
|
+
|
202
|
+
# Constrain the numeric value to be odd.
|
203
|
+
#
|
204
|
+
# @example
|
205
|
+
# type.being_odd
|
206
|
+
# type.validate(3) # => true
|
207
|
+
# type.validate(4) # => false
|
208
|
+
#
|
209
|
+
# @return [self] the current instance for chaining
|
210
|
+
def being_odd: () -> Behavior
|
211
|
+
|
212
|
+
alias odd being_odd
|
213
|
+
|
214
|
+
alias not_being_even being_odd
|
215
|
+
|
216
|
+
# Constrain the numeric value to be positive.
|
217
|
+
#
|
218
|
+
# @example
|
219
|
+
# type.being_positive
|
220
|
+
# type.validate(5) # => true
|
221
|
+
# type.validate(-5) # => false
|
222
|
+
#
|
223
|
+
# @return [self] the current instance for chaining
|
224
|
+
def being_positive: () -> Behavior
|
225
|
+
|
226
|
+
alias positive being_positive
|
227
|
+
|
228
|
+
alias not_being_negative being_positive
|
229
|
+
|
230
|
+
# Constrain the numeric value to be zero.
|
231
|
+
#
|
232
|
+
# @example
|
233
|
+
# type.being_zero
|
234
|
+
# type.validate(0) # => true
|
235
|
+
# type.validate(5) # => false
|
236
|
+
#
|
237
|
+
# @return [self] the current instance for chaining
|
238
|
+
def being_zero: () -> Behavior
|
239
|
+
|
240
|
+
alias zero being_zero
|
241
|
+
|
242
|
+
# Constrain the numeric value to not be divisible by a specific divisor.
|
243
|
+
#
|
244
|
+
# @example
|
245
|
+
# type.not_being_divisible_by(3)
|
246
|
+
# type.validate(5) # => true
|
247
|
+
# type.validate(9) # => false
|
248
|
+
#
|
249
|
+
# @note the divisor MUST be provided as an argument or in the options Hash.
|
250
|
+
#
|
251
|
+
# @param arguments [Array<Numeric>] a list of arguments, typically one divisor
|
252
|
+
# @param options [Hash] additional options such as tolerance for floating-point checks
|
253
|
+
# @option options [Numeric] :divisor the divisor to check for divisibility
|
254
|
+
# @option options [Numeric] :tolerance the tolerance for floating-point checks
|
255
|
+
#
|
256
|
+
# @return [self] the current instance for chaining
|
257
|
+
def not_being_divisible_by: (*Numeric arguments, ?divisor: Numeric, ?tolerance: Numeric) -> Behavior
|
258
|
+
|
259
|
+
alias not_being_multiple_of not_being_divisible_by
|
260
|
+
|
261
|
+
alias not_divisible_by not_being_divisible_by
|
262
|
+
|
263
|
+
alias not_multiple_of not_being_divisible_by
|
264
|
+
|
265
|
+
# Constrain the numeric value to not equal a specific number.
|
266
|
+
#
|
267
|
+
# @example
|
268
|
+
# type.not_being_equal_to(42)
|
269
|
+
# type.validate(7) # => true
|
270
|
+
# type.validate(42) # => false
|
271
|
+
#
|
272
|
+
# @param numeric [Numeric] the number to constrain inequality to
|
273
|
+
#
|
274
|
+
# @return [self] the current instance for chaining
|
275
|
+
def not_being_equal_to: (Numeric numeric) -> Behavior
|
276
|
+
|
277
|
+
alias not_eql not_being_equal_to
|
278
|
+
|
279
|
+
alias not_equal_to not_being_equal_to
|
280
|
+
|
281
|
+
alias not_equaling not_being_equal_to
|
282
|
+
|
283
|
+
# Constrain the numeric value to not be zero.
|
284
|
+
#
|
285
|
+
# @example
|
286
|
+
# type.not_being_zero
|
287
|
+
# type.validate(5) # => true
|
288
|
+
# type.validate(0) # => false
|
289
|
+
#
|
290
|
+
# @return [self] the current instance for chaining
|
291
|
+
def not_being_zero: () -> Behavior
|
292
|
+
|
293
|
+
alias nonzero not_being_zero
|
294
|
+
|
295
|
+
alias not_zero not_being_zero
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
@@ -0,0 +1,218 @@
|
|
1
|
+
module Domainic
|
2
|
+
module Type
|
3
|
+
module Behavior
|
4
|
+
# A module providing size-based validation behaviors for types.
|
5
|
+
#
|
6
|
+
# This module extends the base Type::Behavior with methods specifically designed for validating
|
7
|
+
# the size or length of objects. It provides a consistent interface for size-based validations
|
8
|
+
# across different types (collections, strings, etc) with support for exact, minimum, maximum,
|
9
|
+
# and range-based size constraints.
|
10
|
+
#
|
11
|
+
# Key features:
|
12
|
+
# - Exact size validation
|
13
|
+
# - Minimum/maximum bounds
|
14
|
+
# - Range-based size constraints
|
15
|
+
# - Consistent interface across different types
|
16
|
+
# - Multiple method aliases for intuitive use
|
17
|
+
#
|
18
|
+
# @example Basic usage
|
19
|
+
# class MyType
|
20
|
+
# include Domainic::Type::Behavior::SizableBehavior
|
21
|
+
#
|
22
|
+
# def initialize
|
23
|
+
# super
|
24
|
+
# having_size(5) # exactly 5 elements
|
25
|
+
# having_minimum_size(3) # at least 3 elements
|
26
|
+
# having_maximum_size(10) # at most 10 elements
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# @example Using size ranges
|
31
|
+
# class MyType
|
32
|
+
# include Domainic::Type::Behavior::SizableBehavior
|
33
|
+
#
|
34
|
+
# def initialize
|
35
|
+
# super
|
36
|
+
# having_size_between(5, 10) # between 5 and 10 elements
|
37
|
+
# # Or with keywords
|
38
|
+
# having_size_between(minimum: 5, maximum: 10)
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# @example Method aliases
|
43
|
+
# type.having_size(5) # exact size
|
44
|
+
# type.size(5) # same as above
|
45
|
+
# type.length(5) # same as above
|
46
|
+
# type.count(5) # same as above
|
47
|
+
#
|
48
|
+
# type.having_min_size(3) # minimum size
|
49
|
+
# type.minimum_size(3) # same as above
|
50
|
+
# type.min_length(3) # same as above
|
51
|
+
#
|
52
|
+
# type.having_max_size(10) # maximum size
|
53
|
+
# type.maximum_size(10) # same as above
|
54
|
+
# type.max_length(10) # same as above
|
55
|
+
#
|
56
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
57
|
+
# @since 0.1.0
|
58
|
+
module SizableBehavior
|
59
|
+
# Parse arguments for having_size_between
|
60
|
+
#
|
61
|
+
# @note this in my opinion is better than polluting the namespace of the including class even with a private
|
62
|
+
# method. This way, the method is only available within the module itself. See {#having_size_between}.
|
63
|
+
#
|
64
|
+
# @param minimum [Integer, nil] minimum size value from positional args
|
65
|
+
# @param maximum [Integer, nil] maximum size value from positional args
|
66
|
+
# @param options [Hash] keyword arguments containing min/max values
|
67
|
+
#
|
68
|
+
# @raise [ArgumentError] if minimum or maximum value can't be determined
|
69
|
+
# @return [Array<Integer>] parsed [minimum, maximum] values
|
70
|
+
private def self.parse_having_between_arguments: (Integer? minimum, Integer? maximum, Hash[Symbol, Integer?] options) -> Array[Integer]
|
71
|
+
|
72
|
+
# Raise appropriate ArgumentError for having_size_between
|
73
|
+
#
|
74
|
+
# @param original_caller [Array<String>] caller stack for error
|
75
|
+
# @param minimum [Integer, nil] attempted minimum value
|
76
|
+
# @param maximum [Integer, nil] attempted maximum value
|
77
|
+
# @param options [Hash] keyword arguments that were provided
|
78
|
+
#
|
79
|
+
# @raise [ArgumentError] with appropriate message
|
80
|
+
# @return [void]
|
81
|
+
private def self.raise_having_between_argument_error!: (Array[String] original_caller, Integer? minimum, Integer? maximum, Hash[Symbol, Integer?] options) -> void
|
82
|
+
|
83
|
+
# Set a maximum size constraint
|
84
|
+
#
|
85
|
+
# Creates a constraint ensuring the size of the validated object does not exceed
|
86
|
+
# the specified value.
|
87
|
+
#
|
88
|
+
# @example
|
89
|
+
# type.having_maximum_size(10) # size must be <= 10
|
90
|
+
# type.max_size(10) # same as above
|
91
|
+
# type.maximum_count(10) # same as above
|
92
|
+
#
|
93
|
+
# @param size [Integer] the maximum allowed size
|
94
|
+
# @return [self] for method chaining
|
95
|
+
def having_maximum_size: (Integer size) -> Behavior
|
96
|
+
|
97
|
+
alias having_max_count having_maximum_size
|
98
|
+
|
99
|
+
alias having_max_length having_maximum_size
|
100
|
+
|
101
|
+
alias having_max_size having_maximum_size
|
102
|
+
|
103
|
+
alias having_maximum_count having_maximum_size
|
104
|
+
|
105
|
+
alias having_maximum_length having_maximum_size
|
106
|
+
|
107
|
+
alias max_count having_maximum_size
|
108
|
+
|
109
|
+
alias max_length having_maximum_size
|
110
|
+
|
111
|
+
alias max_size having_maximum_size
|
112
|
+
|
113
|
+
alias maximum_count having_maximum_size
|
114
|
+
|
115
|
+
alias maximum_length having_maximum_size
|
116
|
+
|
117
|
+
alias maximum_size having_maximum_size
|
118
|
+
|
119
|
+
# Set a minimum size constraint
|
120
|
+
#
|
121
|
+
# Creates a constraint ensuring the size of the validated object is at least
|
122
|
+
# the specified value.
|
123
|
+
#
|
124
|
+
# @example
|
125
|
+
# type.having_minimum_size(5) # size must be >= 5
|
126
|
+
# type.min_size(5) # same as above
|
127
|
+
# type.minimum_count(5) # same as above
|
128
|
+
#
|
129
|
+
# @param size [Integer] the minimum required size
|
130
|
+
# @return [self] for method chaining
|
131
|
+
def having_minimum_size: (Integer size) -> Behavior
|
132
|
+
|
133
|
+
alias having_min_count having_minimum_size
|
134
|
+
|
135
|
+
alias having_min_length having_minimum_size
|
136
|
+
|
137
|
+
alias having_min_size having_minimum_size
|
138
|
+
|
139
|
+
alias having_minimum_count having_minimum_size
|
140
|
+
|
141
|
+
alias having_minimum_length having_minimum_size
|
142
|
+
|
143
|
+
alias min_count having_minimum_size
|
144
|
+
|
145
|
+
alias min_length having_minimum_size
|
146
|
+
|
147
|
+
alias min_size having_minimum_size
|
148
|
+
|
149
|
+
alias minimum_count having_minimum_size
|
150
|
+
|
151
|
+
alias minimum_length having_minimum_size
|
152
|
+
|
153
|
+
alias minimum_size having_minimum_size
|
154
|
+
|
155
|
+
# Set an exact size constraint
|
156
|
+
#
|
157
|
+
# Creates a constraint ensuring the size of the validated object equals
|
158
|
+
# the specified value.
|
159
|
+
#
|
160
|
+
# @example
|
161
|
+
# type.having_size(7) # size must be exactly 7
|
162
|
+
# type.size(7) # same as above
|
163
|
+
# type.count(7) # same as above
|
164
|
+
#
|
165
|
+
# @param size [Integer] the required size
|
166
|
+
# @return [self] for method chaining
|
167
|
+
def having_size: (Integer size) -> Behavior
|
168
|
+
|
169
|
+
alias count having_size
|
170
|
+
|
171
|
+
alias having_count having_size
|
172
|
+
|
173
|
+
alias having_length having_size
|
174
|
+
|
175
|
+
alias length having_size
|
176
|
+
|
177
|
+
alias size having_size
|
178
|
+
|
179
|
+
# Set a size range constraint
|
180
|
+
#
|
181
|
+
# Creates a constraint ensuring the size of the validated object falls within
|
182
|
+
# the specified range. The range is exclusive of the minimum and maximum values.
|
183
|
+
#
|
184
|
+
# @example With positional arguments
|
185
|
+
# type.having_size_between(5, 10) # 5 < size < 10
|
186
|
+
#
|
187
|
+
# @example With keyword arguments
|
188
|
+
# type.having_size_between(minimum: 5, maximum: 10)
|
189
|
+
# type.having_size_between(min: 5, max: 10)
|
190
|
+
#
|
191
|
+
# @example With mixed arguments
|
192
|
+
# type.having_size_between(5, max: 10)
|
193
|
+
#
|
194
|
+
# @param minimum [Integer, nil] minimum size value (exclusive)
|
195
|
+
# @param maximum [Integer, nil] maximum size value (exclusive)
|
196
|
+
# @param options [Hash] alternate way to specify min/max
|
197
|
+
# @option options [Integer] :min minimum size (exclusive)
|
198
|
+
# @option options [Integer] :minimum same as :min
|
199
|
+
# @option options [Integer] :max maximum size (exclusive)
|
200
|
+
# @option options [Integer] :maximum same as :max
|
201
|
+
#
|
202
|
+
# @raise [ArgumentError] if minimum or maximum value can't be determined
|
203
|
+
# @return [self] for method chaining
|
204
|
+
def having_size_between: (?Integer? minimum, ?Integer? maximum, ?max: Integer?, ?maximum: Integer?, ?min: Integer?, ?minimum: Integer?) -> Behavior
|
205
|
+
|
206
|
+
alias count_between having_size_between
|
207
|
+
|
208
|
+
alias having_count_between having_size_between
|
209
|
+
|
210
|
+
alias having_length_between having_size_between
|
211
|
+
|
212
|
+
alias length_between having_size_between
|
213
|
+
|
214
|
+
alias size_between having_size_between
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|