domainic-type 0.1.0.alpha.3.2.0 → 0.1.0.alpha.3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +11 -0
- data/README.md +66 -10
- data/docs/USAGE.md +787 -0
- data/lib/domainic/type/accessors.rb +3 -2
- data/lib/domainic/type/behavior/date_time_behavior.rb +121 -37
- data/lib/domainic/type/behavior.rb +16 -0
- data/lib/domainic/type/config/registry.yml +24 -0
- data/lib/domainic/type/constraint/constraints/nor_constraint.rb +1 -1
- data/lib/domainic/type/constraint/constraints/predicate_constraint.rb +76 -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/behavior.rbs +9 -0
- data/sig/domainic/type/constraint/constraints/predicate_constraint.rbs +56 -0
- 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 +25 -6
@@ -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.4.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-30 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
|
@@ -21,9 +21,11 @@ executables: []
|
|
21
21
|
extensions: []
|
22
22
|
extra_rdoc_files: []
|
23
23
|
files:
|
24
|
+
- ".yardopts"
|
24
25
|
- CHANGELOG.md
|
25
26
|
- LICENSE
|
26
27
|
- README.md
|
28
|
+
- docs/USAGE.md
|
27
29
|
- lib/domainic-type.rb
|
28
30
|
- lib/domainic/type.rb
|
29
31
|
- lib/domainic/type/accessors.rb
|
@@ -58,6 +60,7 @@ files:
|
|
58
60
|
- lib/domainic/type/constraint/constraints/ordering_constraint.rb
|
59
61
|
- lib/domainic/type/constraint/constraints/parity_constraint.rb
|
60
62
|
- lib/domainic/type/constraint/constraints/polarity_constraint.rb
|
63
|
+
- lib/domainic/type/constraint/constraints/predicate_constraint.rb
|
61
64
|
- lib/domainic/type/constraint/constraints/range_constraint.rb
|
62
65
|
- lib/domainic/type/constraint/constraints/type_constraint.rb
|
63
66
|
- lib/domainic/type/constraint/constraints/uniqueness_constraint.rb
|
@@ -65,14 +68,21 @@ files:
|
|
65
68
|
- lib/domainic/type/constraint/set.rb
|
66
69
|
- lib/domainic/type/definitions.rb
|
67
70
|
- lib/domainic/type/types/core/array_type.rb
|
71
|
+
- lib/domainic/type/types/core/complex_type.rb
|
68
72
|
- lib/domainic/type/types/core/float_type.rb
|
69
73
|
- lib/domainic/type/types/core/hash_type.rb
|
70
74
|
- lib/domainic/type/types/core/integer_type.rb
|
75
|
+
- lib/domainic/type/types/core/range_type.rb
|
76
|
+
- lib/domainic/type/types/core/rational_type.rb
|
71
77
|
- lib/domainic/type/types/core/string_type.rb
|
72
78
|
- lib/domainic/type/types/core/symbol_type.rb
|
79
|
+
- lib/domainic/type/types/core_extended/big_decimal_type.rb
|
80
|
+
- lib/domainic/type/types/core_extended/set_type.rb
|
81
|
+
- lib/domainic/type/types/datetime/date_time_string_type.rb
|
73
82
|
- lib/domainic/type/types/datetime/date_time_type.rb
|
74
83
|
- lib/domainic/type/types/datetime/date_type.rb
|
75
84
|
- lib/domainic/type/types/datetime/time_type.rb
|
85
|
+
- lib/domainic/type/types/datetime/timestamp_type.rb
|
76
86
|
- lib/domainic/type/types/identifier/cuid_type.rb
|
77
87
|
- lib/domainic/type/types/identifier/uuid_type.rb
|
78
88
|
- lib/domainic/type/types/network/email_address_type.rb
|
@@ -117,6 +127,7 @@ files:
|
|
117
127
|
- sig/domainic/type/constraint/constraints/ordering_constraint.rbs
|
118
128
|
- sig/domainic/type/constraint/constraints/parity_constraint.rbs
|
119
129
|
- sig/domainic/type/constraint/constraints/polarity_constraint.rbs
|
130
|
+
- sig/domainic/type/constraint/constraints/predicate_constraint.rbs
|
120
131
|
- sig/domainic/type/constraint/constraints/range_constraint.rbs
|
121
132
|
- sig/domainic/type/constraint/constraints/type_constraint.rbs
|
122
133
|
- sig/domainic/type/constraint/constraints/uniqueness_constraint.rbs
|
@@ -124,14 +135,21 @@ files:
|
|
124
135
|
- sig/domainic/type/constraint/set.rbs
|
125
136
|
- sig/domainic/type/definitions.rbs
|
126
137
|
- sig/domainic/type/types/core/array_type.rbs
|
138
|
+
- sig/domainic/type/types/core/complex_type.rbs
|
127
139
|
- sig/domainic/type/types/core/float_type.rbs
|
128
140
|
- sig/domainic/type/types/core/hash_type.rbs
|
129
141
|
- sig/domainic/type/types/core/integer_type.rbs
|
142
|
+
- sig/domainic/type/types/core/range_type.rbs
|
143
|
+
- sig/domainic/type/types/core/rational_type.rbs
|
130
144
|
- sig/domainic/type/types/core/string_type.rbs
|
131
145
|
- sig/domainic/type/types/core/symbol_type.rbs
|
146
|
+
- sig/domainic/type/types/core_extended/big_decimal_type.rbs
|
147
|
+
- sig/domainic/type/types/core_extended/set_type.rbs
|
148
|
+
- sig/domainic/type/types/datetime/date_time_string_type.rbs
|
132
149
|
- sig/domainic/type/types/datetime/date_time_type.rbs
|
133
150
|
- sig/domainic/type/types/datetime/date_type.rbs
|
134
151
|
- sig/domainic/type/types/datetime/time_type.rbs
|
152
|
+
- sig/domainic/type/types/datetime/timestamp_type.rbs
|
135
153
|
- sig/domainic/type/types/identifier/cuid_type.rbs
|
136
154
|
- sig/domainic/type/types/identifier/uuid_type.rbs
|
137
155
|
- sig/domainic/type/types/network/email_address_type.rbs
|
@@ -144,15 +162,16 @@ files:
|
|
144
162
|
- sig/domainic/type/types/specification/union_type.rbs
|
145
163
|
- sig/domainic/type/types/specification/void_type.rbs
|
146
164
|
- sig/manifest.yaml
|
147
|
-
homepage: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.
|
165
|
+
homepage: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.4.0/domainic-type
|
148
166
|
licenses:
|
149
167
|
- MIT
|
150
168
|
metadata:
|
151
169
|
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
|
-
|
170
|
+
changelog_uri: https://github.com/domainic/domainic/releases/tag/domainic-type-v0.1.0-alpha.3.4.0
|
171
|
+
documentation_uri: https://rubydoc.info/gems/domainic-type/0.1.0.alpha.3.4.0
|
172
|
+
homepage_uri: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.4.0/domainic-type
|
154
173
|
rubygems_mfa_required: 'true'
|
155
|
-
source_code_uri: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.
|
174
|
+
source_code_uri: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.4.0/domainic-type
|
156
175
|
post_install_message:
|
157
176
|
rdoc_options: []
|
158
177
|
require_paths:
|