domainic-type 0.1.0.alpha.3.2.0 → 0.1.0.alpha.3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +66 -10
- data/docs/USAGE.md +732 -0
- data/lib/domainic/type/accessors.rb +3 -2
- data/lib/domainic/type/behavior/date_time_behavior.rb +117 -37
- data/lib/domainic/type/config/registry.yml +21 -0
- data/lib/domainic/type/definitions.rb +212 -0
- data/lib/domainic/type/types/core/complex_type.rb +122 -0
- data/lib/domainic/type/types/core/range_type.rb +47 -0
- data/lib/domainic/type/types/core/rational_type.rb +38 -0
- data/lib/domainic/type/types/core_extended/big_decimal_type.rb +34 -0
- data/lib/domainic/type/types/core_extended/set_type.rb +34 -0
- data/lib/domainic/type/types/datetime/date_time_string_type.rb +156 -0
- data/lib/domainic/type/types/datetime/timestamp_type.rb +50 -0
- data/sig/domainic/type/accessors.rbs +2 -2
- data/sig/domainic/type/behavior/date_time_behavior.rbs +35 -23
- data/sig/domainic/type/definitions.rbs +165 -0
- data/sig/domainic/type/types/core/complex_type.rbs +96 -0
- data/sig/domainic/type/types/core/range_type.rbs +41 -0
- data/sig/domainic/type/types/core/rational_type.rbs +32 -0
- data/sig/domainic/type/types/core_extended/big_decimal_type.rbs +27 -0
- data/sig/domainic/type/types/core_extended/set_type.rbs +27 -0
- data/sig/domainic/type/types/datetime/date_time_string_type.rbs +124 -0
- data/sig/domainic/type/types/datetime/timestamp_type.rbs +44 -0
- metadata +21 -6
@@ -64,6 +64,29 @@ module Domainic
|
|
64
64
|
|
65
65
|
alias _List? _Array?
|
66
66
|
|
67
|
+
# Creates a BigDecimalType instance.
|
68
|
+
#
|
69
|
+
# @example
|
70
|
+
# type = _BigDecimal
|
71
|
+
# type.validate(BigDecimal('123.45')) # => true
|
72
|
+
#
|
73
|
+
# @param options [Hash] additional configuration options
|
74
|
+
#
|
75
|
+
# @return [Domainic::Type::BigDecimalType] the created type
|
76
|
+
def _BigDecimal: (**__todo__ options) -> BigDecimalType
|
77
|
+
|
78
|
+
# Creates a nilable BigDecimalType instance.
|
79
|
+
#
|
80
|
+
# @example
|
81
|
+
# type = _BigDecimal?
|
82
|
+
# type.validate(BigDecimal('123.45')) # => true
|
83
|
+
# type.validate(nil) # => true
|
84
|
+
#
|
85
|
+
# @param options [Hash] additional configuration options
|
86
|
+
#
|
87
|
+
# @return [Domainic::Type::UnionType] the created type (BigDecimal or NilClass)
|
88
|
+
def _BigDecimal?: (**__todo__ options) -> UnionType
|
89
|
+
|
67
90
|
# Creates a Boolean type.
|
68
91
|
#
|
69
92
|
# Represents a union of TrueClass and FalseClass.
|
@@ -111,6 +134,28 @@ module Domainic
|
|
111
134
|
|
112
135
|
alias _Cuid? _CUID?
|
113
136
|
|
137
|
+
# Creates a ComplexType instance.
|
138
|
+
#
|
139
|
+
# @example
|
140
|
+
# type = _Complex
|
141
|
+
# type.validate(Complex(1, 2)) # => true
|
142
|
+
#
|
143
|
+
# @param options [Hash] additional configuration options
|
144
|
+
#
|
145
|
+
# @return [Domainic::Type::ComplexType] the created type
|
146
|
+
def _Complex: (**__todo__ options) -> ComplexType
|
147
|
+
|
148
|
+
# Creates a nilable ComplexType instance.
|
149
|
+
#
|
150
|
+
# @example
|
151
|
+
# type = _Complex?
|
152
|
+
# type.validate(Complex(1, 2)) # => true
|
153
|
+
#
|
154
|
+
# @param options [Hash] additional configuration options
|
155
|
+
#
|
156
|
+
# @return [Domainic::Type::UnionType] the created type (Complex or NilClass)
|
157
|
+
def _Complex?: (**__todo__ options) -> UnionType
|
158
|
+
|
114
159
|
# Creates a DateType instance.
|
115
160
|
#
|
116
161
|
# DateType restricts values to valid `Date` objects.
|
@@ -159,6 +204,34 @@ module Domainic
|
|
159
204
|
# @return [Domainic::Type::UnionType] the created type (DateTimeType or NilClass)
|
160
205
|
def _DateTime?: (**__todo__ options) -> UnionType
|
161
206
|
|
207
|
+
# Creates a DateTimeStringType instance.
|
208
|
+
#
|
209
|
+
# DateTimeStringType restricts values to valid date-time strings.
|
210
|
+
#
|
211
|
+
# @example
|
212
|
+
# type = _DateTimeString
|
213
|
+
# type.validate('2024-01-01T12:00:00Z') # => true
|
214
|
+
#
|
215
|
+
# @param options [Hash] additional configuration options
|
216
|
+
#
|
217
|
+
# @return [Domainic::Type::DateTimeStringType] the created type
|
218
|
+
def _DateTimeString: (**__todo__ options) -> DateTimeStringType
|
219
|
+
|
220
|
+
alias _DateString _DateTimeString
|
221
|
+
|
222
|
+
# Creates a nilable DateTimeStringType instance.
|
223
|
+
#
|
224
|
+
# @example
|
225
|
+
# _DateTimeString? === '2024-01-01T12:00:00Z' # => true
|
226
|
+
# _DateTimeString? === nil # => true
|
227
|
+
#
|
228
|
+
# @param options [Hash] additional configuration options
|
229
|
+
#
|
230
|
+
# @return [Domainic::Type::UnionType] the created type (DateTimeStringType or NilClass)
|
231
|
+
def _DateTimeString?: (**__todo__ options) -> UnionType
|
232
|
+
|
233
|
+
alias _DateString? _DateTimeString?
|
234
|
+
|
162
235
|
# Creates a DuckType instance.
|
163
236
|
#
|
164
237
|
# DuckType allows specifying behavior based on method availability.
|
@@ -395,6 +468,74 @@ module Domainic
|
|
395
468
|
|
396
469
|
alias _Nullable _Nilable
|
397
470
|
|
471
|
+
# Creates a RangeType instance.
|
472
|
+
#
|
473
|
+
# @example
|
474
|
+
# type = _Range
|
475
|
+
# type.validate(1..10) # => true
|
476
|
+
#
|
477
|
+
# @param options [Hash] additional configuration options
|
478
|
+
#
|
479
|
+
# @return [Domainic::Type::RangeType] the created type
|
480
|
+
def _Range: (**__todo__ options) -> RangeType
|
481
|
+
|
482
|
+
# Creates a nilable RangeType instance.
|
483
|
+
#
|
484
|
+
# @example
|
485
|
+
# type = _Range?
|
486
|
+
# type.validate(1..10) # => true
|
487
|
+
#
|
488
|
+
# @param options [Hash] additional configuration options
|
489
|
+
#
|
490
|
+
# @return [Domainic::Type::UnionType] the created type (Range or NilClass)
|
491
|
+
def _Range?: (**__todo__ options) -> UnionType
|
492
|
+
|
493
|
+
# Creates a RationalType instance.
|
494
|
+
#
|
495
|
+
# @example
|
496
|
+
# type = _Rational
|
497
|
+
# type.validate(Rational(1, 2)) # => true
|
498
|
+
#
|
499
|
+
# @param options [Hash] additional configuration options
|
500
|
+
#
|
501
|
+
# @return [Domainic::Type::RationalType] the created type
|
502
|
+
def _Rational: (**__todo__ options) -> RationalType
|
503
|
+
|
504
|
+
# Creates a nilable RationalType instance.
|
505
|
+
#
|
506
|
+
# @example
|
507
|
+
# type = _Rational?
|
508
|
+
# type.validate(Rational(1, 2)) # => true
|
509
|
+
# type.validate(nil) # => true
|
510
|
+
#
|
511
|
+
# @param options [Hash] additional configuration options
|
512
|
+
#
|
513
|
+
# @return [Domainic::Type::UnionType] the created type (Rational or NilClass)
|
514
|
+
def _Rational?: (**__todo__ options) -> UnionType
|
515
|
+
|
516
|
+
# Creates a SetType instance.
|
517
|
+
#
|
518
|
+
# @example
|
519
|
+
# type = _Set
|
520
|
+
# type.validate(Set[1, 2, 3]) # => true
|
521
|
+
#
|
522
|
+
# @param options [Hash] additional configuration options
|
523
|
+
#
|
524
|
+
# @return [Domainic::Type::SetType] the created type
|
525
|
+
def _Set: (**__todo__ options) -> SetType
|
526
|
+
|
527
|
+
# Creates a nilable SetType instance.
|
528
|
+
#
|
529
|
+
# @example
|
530
|
+
# type = _Set?
|
531
|
+
# type.validate(Set[1, 2, 3]) # => true
|
532
|
+
# type.validate(nil) # => true
|
533
|
+
#
|
534
|
+
# @param options [Hash] additional configuration options
|
535
|
+
#
|
536
|
+
# @return [Domainic::Type::UnionType] the created type (Set or NilClass)
|
537
|
+
def _Set?: (**__todo__ options) -> UnionType
|
538
|
+
|
398
539
|
# Creates a StringType instance.
|
399
540
|
#
|
400
541
|
# @example
|
@@ -467,6 +608,30 @@ module Domainic
|
|
467
608
|
# @return [Domainic::Type::UnionType] the created type (TimeType or NilClass)
|
468
609
|
def _Time?: (**__todo__ options) -> UnionType
|
469
610
|
|
611
|
+
# Creates a TimestampType instance.
|
612
|
+
#
|
613
|
+
# TimestampType restricts values to valid timestamps.
|
614
|
+
#
|
615
|
+
# @example
|
616
|
+
# type = _Timestamp
|
617
|
+
# type.validate(1640995200) # => true
|
618
|
+
#
|
619
|
+
# @param options [Hash] additional configuration options
|
620
|
+
#
|
621
|
+
# @return [Domainic::Type::TimestampType] the created type
|
622
|
+
def _Timestamp: (**__todo__ options) -> TimestampType
|
623
|
+
|
624
|
+
# Creates a nilable TimestampType instance.
|
625
|
+
#
|
626
|
+
# @example
|
627
|
+
# _Timestamp? === 1640995200 # => true
|
628
|
+
# _Timestamp? === nil # => true
|
629
|
+
#
|
630
|
+
# @param options [Hash] additional configuration options
|
631
|
+
#
|
632
|
+
# @return [Domainic::Type::UnionType] the created type (TimestampType or NilClass)
|
633
|
+
def _Timestamp?: (**__todo__ options) -> UnionType
|
634
|
+
|
470
635
|
# Creates a URIType instance.
|
471
636
|
#
|
472
637
|
# URIType restricts values to valid URIs.
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Domainic
|
2
|
+
module Type
|
3
|
+
# A type for validating and constraining `Complex` numbers.
|
4
|
+
#
|
5
|
+
# This type extends `NumericBehavior` to provide a fluent interface for numeric-specific validations such as
|
6
|
+
# polarity and divisibility checks.
|
7
|
+
#
|
8
|
+
# @example Validating a `Complex` value
|
9
|
+
# type = Domainic::Type::ComplexType.new
|
10
|
+
# type.validate!(Complex(3, 4)) # => true
|
11
|
+
#
|
12
|
+
# @example Enforcing constraints
|
13
|
+
# type = Domainic::Type::ComplexType.new
|
14
|
+
# type.being_positive.validate!(Complex(42, 0)) # => raises TypeError
|
15
|
+
#
|
16
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
17
|
+
# @since 0.1.0
|
18
|
+
class ComplexType
|
19
|
+
extend Behavior::ClassMethods
|
20
|
+
|
21
|
+
include Behavior
|
22
|
+
|
23
|
+
include Behavior::NumericBehavior
|
24
|
+
|
25
|
+
# Constrain the Complex real to be divisible by a given divisor.
|
26
|
+
#
|
27
|
+
# @param arguments [Array<Numeric>] a list of arguments, typically one divisor
|
28
|
+
# @param options [Hash] additional options such as tolerance for floating-point checks
|
29
|
+
# @option options [Numeric] :divisor the divisor to check for divisibility
|
30
|
+
# @option options [Numeric] :tolerance the tolerance for floating-point checks
|
31
|
+
#
|
32
|
+
# @return [self] the current instance for chaining
|
33
|
+
def being_divisible_by: (*Numeric arguments, ?divisor: Numeric, ?tolerance: Numeric) -> Behavior
|
34
|
+
|
35
|
+
alias being_multiple_of being_divisible_by
|
36
|
+
|
37
|
+
alias divisible_by being_divisible_by
|
38
|
+
|
39
|
+
alias multiple_of being_divisible_by
|
40
|
+
|
41
|
+
# Constrain the Complex real to be even.
|
42
|
+
#
|
43
|
+
# @return [self] the current instance for chaining
|
44
|
+
def being_even: () -> Behavior
|
45
|
+
|
46
|
+
alias even being_even
|
47
|
+
|
48
|
+
alias not_being_odd being_even
|
49
|
+
|
50
|
+
# Constrain the Complex real to be negative.
|
51
|
+
#
|
52
|
+
# @return [self] the current instance for chaining
|
53
|
+
def being_negative: () -> Behavior
|
54
|
+
|
55
|
+
alias negative being_negative
|
56
|
+
|
57
|
+
alias not_being_positive being_negative
|
58
|
+
|
59
|
+
# Constrain the Complex real value to be odd.
|
60
|
+
#
|
61
|
+
# @return [self] the current instance for chaining
|
62
|
+
def being_odd: () -> Behavior
|
63
|
+
|
64
|
+
alias odd being_odd
|
65
|
+
|
66
|
+
alias not_being_even being_odd
|
67
|
+
|
68
|
+
# Constrain the Complex real to be positive.
|
69
|
+
#
|
70
|
+
# @return [self] the current instance for chaining
|
71
|
+
def being_positive: () -> Behavior
|
72
|
+
|
73
|
+
alias positive being_positive
|
74
|
+
|
75
|
+
alias not_being_negative being_positive
|
76
|
+
|
77
|
+
# Constrain the Complex real to not be divisible by a specific divisor.
|
78
|
+
#
|
79
|
+
# @note the divisor MUST be provided as an argument or in the options Hash.
|
80
|
+
#
|
81
|
+
# @param arguments [Array<Numeric>] a list of arguments, typically one divisor
|
82
|
+
# @param options [Hash] additional options such as tolerance for floating-point checks
|
83
|
+
# @option options [Numeric] :divisor the divisor to check for divisibility
|
84
|
+
# @option options [Numeric] :tolerance the tolerance for floating-point checks
|
85
|
+
#
|
86
|
+
# @return [self] the current instance for chaining
|
87
|
+
def not_being_divisible_by: (*Numeric arguments, ?divisor: Numeric, ?tolerance: Numeric) -> Behavior
|
88
|
+
|
89
|
+
alias not_being_multiple_of not_being_divisible_by
|
90
|
+
|
91
|
+
alias not_divisible_by not_being_divisible_by
|
92
|
+
|
93
|
+
alias not_multiple_of not_being_divisible_by
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Domainic
|
2
|
+
module Type
|
3
|
+
# A type for validating `Range` objects with comprehensive constraints.
|
4
|
+
#
|
5
|
+
# This class allows flexible validation of ranges, supporting type checks,
|
6
|
+
# inclusion/exclusion of values, and range-specific behaviors such as bounds validation.
|
7
|
+
# It integrates with `EnumerableBehavior` for enumerable-style validations
|
8
|
+
# (e.g., size constraints, element presence).
|
9
|
+
#
|
10
|
+
# Key features:
|
11
|
+
# - Ensures the value is a `Range`.
|
12
|
+
# - Supports constraints for range boundaries (`begin` and `end`).
|
13
|
+
# - Provides validations for inclusion and exclusion of values.
|
14
|
+
# - Leverages `EnumerableBehavior` for size and collection-style constraints.
|
15
|
+
#
|
16
|
+
# @example Basic usage
|
17
|
+
# type = RangeType.new
|
18
|
+
# type.having_bounds(1, 10) # Validates range bounds (inclusive or exclusive).
|
19
|
+
# type.containing(5) # Ensures value is within the range.
|
20
|
+
# type.not_containing(15) # Ensures value is not within the range.
|
21
|
+
#
|
22
|
+
# @example Integration with EnumerableBehavior
|
23
|
+
# type = RangeType.new
|
24
|
+
# type.having_size(10) # Validates size (total elements in the range).
|
25
|
+
# type.containing_exactly(3, 7) # Validates specific values within the range.
|
26
|
+
#
|
27
|
+
# @example Flexible boundaries
|
28
|
+
# type = RangeType.new
|
29
|
+
# type.having_bounds(1, 10, exclusive: true) # Upper and lower bounds are exclusive.
|
30
|
+
#
|
31
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
32
|
+
# @since 0.1.0
|
33
|
+
class RangeType
|
34
|
+
extend Behavior::ClassMethods
|
35
|
+
|
36
|
+
include Behavior
|
37
|
+
|
38
|
+
include Behavior::EnumerableBehavior
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Domainic
|
2
|
+
module Type
|
3
|
+
# A type for validating Rational numbers.
|
4
|
+
#
|
5
|
+
# This type ensures values are of type `Rational` and supports a range of
|
6
|
+
# constraints for numerical validation, such as positivity, negativity,
|
7
|
+
# and divisibility. It integrates with `NumericBehavior` to provide a
|
8
|
+
# consistent and fluent interface for numeric constraints.
|
9
|
+
#
|
10
|
+
# @example Validating a positive Rational number
|
11
|
+
# type = Domainic::Type::RationalType.new
|
12
|
+
# type.being_positive.validate!(Rational(3, 4)) # => true
|
13
|
+
#
|
14
|
+
# @example Validating divisibility
|
15
|
+
# type = Domainic::Type::RationalType.new
|
16
|
+
# type.being_divisible_by(1).validate!(Rational(3, 1)) # => true
|
17
|
+
#
|
18
|
+
# @example Using constraints with chaining
|
19
|
+
# type = Domainic::Type::RationalType.new
|
20
|
+
# type.being_greater_than(0).being_less_than(1).validate!(Rational(1, 2)) # => true
|
21
|
+
#
|
22
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
23
|
+
# @since 0.1.0
|
24
|
+
class RationalType
|
25
|
+
extend Behavior::ClassMethods
|
26
|
+
|
27
|
+
include Behavior
|
28
|
+
|
29
|
+
include Behavior::NumericBehavior
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Domainic
|
2
|
+
module Type
|
3
|
+
# A type for validating and constraining `BigDecimal` objects.
|
4
|
+
#
|
5
|
+
# This type extends `NumericBehavior` to provide a fluent interface for numeric-specific validations such as being
|
6
|
+
# positive, being within a range, or satisfying divisibility rules.
|
7
|
+
#
|
8
|
+
# @example Validating a `BigDecimal` value
|
9
|
+
# type = Domainic::Type::BigDecimalType.new
|
10
|
+
# type.validate!(BigDecimal('3.14')) # => true
|
11
|
+
#
|
12
|
+
# @example Enforcing constraints
|
13
|
+
# type = Domainic::Type::BigDecimalType.new
|
14
|
+
# type.being_positive.validate!(BigDecimal('42')) # => true
|
15
|
+
# type.being_positive.validate!(BigDecimal('-42')) # raises TypeError
|
16
|
+
#
|
17
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
18
|
+
# @since 0.1.0
|
19
|
+
class BigDecimalType
|
20
|
+
extend Behavior::ClassMethods
|
21
|
+
|
22
|
+
include Behavior
|
23
|
+
|
24
|
+
include Behavior::NumericBehavior
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Domainic
|
2
|
+
module Type
|
3
|
+
# A type for validating and constraining `Set` objects.
|
4
|
+
#
|
5
|
+
# This type extends `EnumerableBehavior` to support validations and constraints
|
6
|
+
# such as being empty, containing specific elements, or having a minimum or maximum count.
|
7
|
+
#
|
8
|
+
# @example Validating a `Set` object
|
9
|
+
# type = Domainic::Type::SetType.new
|
10
|
+
# type.validate!(Set.new([1, 2, 3])) # => true
|
11
|
+
#
|
12
|
+
# @example Enforcing constraints
|
13
|
+
# type = Domainic::Type::SetType.new
|
14
|
+
# type.being_empty.validate!(Set.new) # => true
|
15
|
+
# type.being_empty.validate!(Set.new([1])) # raises TypeError
|
16
|
+
#
|
17
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
18
|
+
# @since 0.1.0
|
19
|
+
class SetType
|
20
|
+
extend Behavior::ClassMethods
|
21
|
+
|
22
|
+
include Behavior
|
23
|
+
|
24
|
+
include Behavior::EnumerableBehavior
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Domainic
|
2
|
+
module Type
|
3
|
+
# A type for validating and constraining strings to match various datetime formats.
|
4
|
+
#
|
5
|
+
# This class includes behaviors for handling datetime constraints and ensures that
|
6
|
+
# a string matches one of the predefined datetime formats (e.g., ISO 8601, RFC2822).
|
7
|
+
#
|
8
|
+
# @example Validating American format
|
9
|
+
# type = Domainic::Type::DateTimeStringType.new
|
10
|
+
# type.having_american_format.validate!("01/31/2024")
|
11
|
+
#
|
12
|
+
# @example Validating ISO 8601 format
|
13
|
+
# type = Domainic::Type::DateTimeStringType.new
|
14
|
+
# type.having_iso8601_format.validate!("2024-01-01T12:00:00Z")
|
15
|
+
#
|
16
|
+
# @example Validating RFC2822 format
|
17
|
+
# type = Domainic::Type::DateTimeStringType.new
|
18
|
+
# type.having_rfc2822_format.validate!("Thu, 31 Jan 2024 13:30:00 +0000")
|
19
|
+
#
|
20
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
21
|
+
# @since 0.1.0
|
22
|
+
class DateTimeStringType
|
23
|
+
extend Behavior::ClassMethods
|
24
|
+
|
25
|
+
include Behavior
|
26
|
+
|
27
|
+
include Behavior::DateTimeBehavior
|
28
|
+
|
29
|
+
# The `Format` module provides a set of regular expressions for validating
|
30
|
+
# various datetime formats, including ISO 8601, RFC2822, American, European,
|
31
|
+
# full month names, abbreviated month names, and 12-hour clock formats.
|
32
|
+
#
|
33
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
34
|
+
# @since 0.1.0
|
35
|
+
module Format
|
36
|
+
# Matches ISO 8601 datetime formats, including:
|
37
|
+
# - `2024-01-01T12:00:00.000+00:00`
|
38
|
+
# - `2024-01-01T12:00:00+00:00`
|
39
|
+
# - `2024-01-01T12:00:00.000`
|
40
|
+
# - `2024-01-01T12:00:00`
|
41
|
+
# - `20240101T120000+0000` (basic format)
|
42
|
+
# @return [Regexp]
|
43
|
+
ISO8601: Regexp
|
44
|
+
|
45
|
+
# Matches RFC2822 datetime formats, including:
|
46
|
+
# - `Thu, 31 Jan 2024 13:30:00 +0000`
|
47
|
+
# - `31 Jan 2024 13:30:00 +0000`
|
48
|
+
# @return [Regexp]
|
49
|
+
RFC2822: Regexp
|
50
|
+
|
51
|
+
# Matches American-style dates with optional time in 12-hour or 24-hour formats, including:
|
52
|
+
# - `01/31/2024`
|
53
|
+
# - `01/31/2024 12:30:00`
|
54
|
+
# - `01/31/2024 12:30 PM`
|
55
|
+
# @return [Regexp]
|
56
|
+
AMERICAN: Regexp
|
57
|
+
|
58
|
+
# Matches European-style dates with optional time in 24-hour format, including:
|
59
|
+
# - `31.01.2024`
|
60
|
+
# - `31.01.2024 12:30:00`
|
61
|
+
# @return [Regexp]
|
62
|
+
EUROPEAN: Regexp
|
63
|
+
|
64
|
+
# Matches datetime formats with full month names, including:
|
65
|
+
# - `January 31, 2024 12:00:00`
|
66
|
+
# - `January 31, 2024 12:00`
|
67
|
+
# @return [Regexp]
|
68
|
+
FULL_MONTH_NAME: Regexp
|
69
|
+
|
70
|
+
# Matches datetime formats with abbreviated month names, including:
|
71
|
+
# - `Jan 31, 2024 12:00:00`
|
72
|
+
# - `Jan 31, 2024 12:00`
|
73
|
+
# @return [Regexp]
|
74
|
+
ABBREVIATED_MONTH_NAME: Regexp
|
75
|
+
|
76
|
+
# Matches datetime formats using a 12-hour clock with AM/PM, including:
|
77
|
+
# - `2024-01-01 01:30:00 PM`
|
78
|
+
# - `2024-01-01 01:30 PM`
|
79
|
+
# @return [Regexp]
|
80
|
+
TWELVE_HOUR_FORMAT: Regexp
|
81
|
+
end
|
82
|
+
|
83
|
+
# Constrain the type to match American-style datetime formats.
|
84
|
+
#
|
85
|
+
# @return [self] self for method chaining
|
86
|
+
def having_american_format: () -> self
|
87
|
+
|
88
|
+
alias american having_american_format
|
89
|
+
|
90
|
+
alias having_us_format having_american_format
|
91
|
+
|
92
|
+
alias us_format having_american_format
|
93
|
+
|
94
|
+
# Constrain the type to match European-style datetime formats.
|
95
|
+
#
|
96
|
+
# @return [self] self for method chaining
|
97
|
+
def having_european_format: () -> self
|
98
|
+
|
99
|
+
alias european having_european_format
|
100
|
+
|
101
|
+
alias having_eu_format having_european_format
|
102
|
+
|
103
|
+
alias eu_format having_european_format
|
104
|
+
|
105
|
+
# Constrain the type to match ISO 8601 datetime formats.
|
106
|
+
#
|
107
|
+
# @return [self] self for method chaining
|
108
|
+
def having_iso8601_format: () -> self
|
109
|
+
|
110
|
+
alias iso8601 having_iso8601_format
|
111
|
+
|
112
|
+
alias iso8601_format having_iso8601_format
|
113
|
+
|
114
|
+
# Constrain the type to match RFC2822 datetime formats.
|
115
|
+
#
|
116
|
+
# @return [self] self for method chaining
|
117
|
+
def having_rfc2822_format: () -> self
|
118
|
+
|
119
|
+
alias rfc2822 having_rfc2822_format
|
120
|
+
|
121
|
+
alias rfc2822_format having_rfc2822_format
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Domainic
|
2
|
+
module Type
|
3
|
+
# A type for validating Unix timestamps (seconds since the Unix epoch).
|
4
|
+
#
|
5
|
+
# This type ensures the value is an `Integer` representing a valid Unix
|
6
|
+
# timestamp. It integrates with `DateTimeBehavior` to provide a rich set of
|
7
|
+
# validation capabilities, including chronological constraints and range checks.
|
8
|
+
#
|
9
|
+
# Key features:
|
10
|
+
# - Ensures the value is an `Integer` representing a Unix timestamp.
|
11
|
+
# - Supports chronological relationship constraints (e.g., before, after).
|
12
|
+
# - Provides range, equality, and nilable checks.
|
13
|
+
#
|
14
|
+
# @example Basic usage
|
15
|
+
# type = TimestampType.new
|
16
|
+
# type.validate(Time.now.to_i) # => true
|
17
|
+
# type.validate(Date.today.to_time.to_i) # => true
|
18
|
+
# type.validate('invalid') # => false
|
19
|
+
#
|
20
|
+
# @example Range validation
|
21
|
+
# type = TimestampType.new
|
22
|
+
# .being_between(Time.now.to_i, (Time.now + 3600).to_i)
|
23
|
+
# type.validate((Time.now + 1800).to_i) # => true
|
24
|
+
# type.validate((Time.now + 7200).to_i) # => false
|
25
|
+
#
|
26
|
+
# @example Historical timestamps
|
27
|
+
# type = TimestampType.new
|
28
|
+
# type.validate(-1234567890) # => true (date before 1970-01-01)
|
29
|
+
#
|
30
|
+
# @example Nilable timestamp
|
31
|
+
# nilable_type = _Nilable(TimestampType.new)
|
32
|
+
# nilable_type.validate(nil) # => true
|
33
|
+
#
|
34
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
35
|
+
# @since 0.1.0
|
36
|
+
class TimestampType
|
37
|
+
extend Behavior::ClassMethods
|
38
|
+
|
39
|
+
include Behavior
|
40
|
+
|
41
|
+
include Behavior::DateTimeBehavior
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: domainic-type
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.alpha.3.
|
4
|
+
version: 0.1.0.alpha.3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Allen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Stop wrestling with complex type validations and unclear error messages.
|
14
14
|
Domainic::Type brings type validation to Ruby that is both powerful and delightful
|
@@ -24,6 +24,7 @@ files:
|
|
24
24
|
- CHANGELOG.md
|
25
25
|
- LICENSE
|
26
26
|
- README.md
|
27
|
+
- docs/USAGE.md
|
27
28
|
- lib/domainic-type.rb
|
28
29
|
- lib/domainic/type.rb
|
29
30
|
- lib/domainic/type/accessors.rb
|
@@ -65,14 +66,21 @@ files:
|
|
65
66
|
- lib/domainic/type/constraint/set.rb
|
66
67
|
- lib/domainic/type/definitions.rb
|
67
68
|
- lib/domainic/type/types/core/array_type.rb
|
69
|
+
- lib/domainic/type/types/core/complex_type.rb
|
68
70
|
- lib/domainic/type/types/core/float_type.rb
|
69
71
|
- lib/domainic/type/types/core/hash_type.rb
|
70
72
|
- lib/domainic/type/types/core/integer_type.rb
|
73
|
+
- lib/domainic/type/types/core/range_type.rb
|
74
|
+
- lib/domainic/type/types/core/rational_type.rb
|
71
75
|
- lib/domainic/type/types/core/string_type.rb
|
72
76
|
- lib/domainic/type/types/core/symbol_type.rb
|
77
|
+
- lib/domainic/type/types/core_extended/big_decimal_type.rb
|
78
|
+
- lib/domainic/type/types/core_extended/set_type.rb
|
79
|
+
- lib/domainic/type/types/datetime/date_time_string_type.rb
|
73
80
|
- lib/domainic/type/types/datetime/date_time_type.rb
|
74
81
|
- lib/domainic/type/types/datetime/date_type.rb
|
75
82
|
- lib/domainic/type/types/datetime/time_type.rb
|
83
|
+
- lib/domainic/type/types/datetime/timestamp_type.rb
|
76
84
|
- lib/domainic/type/types/identifier/cuid_type.rb
|
77
85
|
- lib/domainic/type/types/identifier/uuid_type.rb
|
78
86
|
- lib/domainic/type/types/network/email_address_type.rb
|
@@ -124,14 +132,21 @@ files:
|
|
124
132
|
- sig/domainic/type/constraint/set.rbs
|
125
133
|
- sig/domainic/type/definitions.rbs
|
126
134
|
- sig/domainic/type/types/core/array_type.rbs
|
135
|
+
- sig/domainic/type/types/core/complex_type.rbs
|
127
136
|
- sig/domainic/type/types/core/float_type.rbs
|
128
137
|
- sig/domainic/type/types/core/hash_type.rbs
|
129
138
|
- sig/domainic/type/types/core/integer_type.rbs
|
139
|
+
- sig/domainic/type/types/core/range_type.rbs
|
140
|
+
- sig/domainic/type/types/core/rational_type.rbs
|
130
141
|
- sig/domainic/type/types/core/string_type.rbs
|
131
142
|
- sig/domainic/type/types/core/symbol_type.rbs
|
143
|
+
- sig/domainic/type/types/core_extended/big_decimal_type.rbs
|
144
|
+
- sig/domainic/type/types/core_extended/set_type.rbs
|
145
|
+
- sig/domainic/type/types/datetime/date_time_string_type.rbs
|
132
146
|
- sig/domainic/type/types/datetime/date_time_type.rbs
|
133
147
|
- sig/domainic/type/types/datetime/date_type.rbs
|
134
148
|
- sig/domainic/type/types/datetime/time_type.rbs
|
149
|
+
- sig/domainic/type/types/datetime/timestamp_type.rbs
|
135
150
|
- sig/domainic/type/types/identifier/cuid_type.rbs
|
136
151
|
- sig/domainic/type/types/identifier/uuid_type.rbs
|
137
152
|
- sig/domainic/type/types/network/email_address_type.rbs
|
@@ -144,15 +159,15 @@ files:
|
|
144
159
|
- sig/domainic/type/types/specification/union_type.rbs
|
145
160
|
- sig/domainic/type/types/specification/void_type.rbs
|
146
161
|
- sig/manifest.yaml
|
147
|
-
homepage: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.
|
162
|
+
homepage: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.3.0/domainic-type
|
148
163
|
licenses:
|
149
164
|
- MIT
|
150
165
|
metadata:
|
151
166
|
bug_tracker_uri: https://github.com/domainic/domainic/issues
|
152
|
-
changelog_uri: https://github.com/domainic/domainic/releases/tag/domainic-type-v0.1.0-alpha.3.
|
153
|
-
homepage_uri: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.
|
167
|
+
changelog_uri: https://github.com/domainic/domainic/releases/tag/domainic-type-v0.1.0-alpha.3.3.0
|
168
|
+
homepage_uri: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.3.0/domainic-type
|
154
169
|
rubygems_mfa_required: 'true'
|
155
|
-
source_code_uri: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.
|
170
|
+
source_code_uri: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.3.0/domainic-type
|
156
171
|
post_install_message:
|
157
172
|
rdoc_options: []
|
158
173
|
require_paths:
|