domainic-type 0.1.0.alpha.3.0.2 → 0.1.0.alpha.3.1.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.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/lib/domainic/type/behavior/string_behavior/matching_behavior.rb +115 -0
  3. data/lib/domainic/type/behavior/string_behavior.rb +2 -111
  4. data/lib/domainic/type/behavior/uri_behavior.rb +97 -0
  5. data/lib/domainic/type/behavior.rb +21 -1
  6. data/lib/domainic/type/config/registry.yml +15 -0
  7. data/lib/domainic/type/definitions.rb +182 -1
  8. data/lib/domainic/type/types/core/array_type.rb +1 -1
  9. data/lib/domainic/type/types/core/float_type.rb +1 -1
  10. data/lib/domainic/type/types/core/hash_type.rb +1 -1
  11. data/lib/domainic/type/types/core/integer_type.rb +1 -1
  12. data/lib/domainic/type/types/core/string_type.rb +1 -1
  13. data/lib/domainic/type/types/core/symbol_type.rb +1 -1
  14. data/lib/domainic/type/types/identifier/cuid_type.rb +140 -0
  15. data/lib/domainic/type/types/identifier/uuid_type.rb +513 -0
  16. data/lib/domainic/type/types/network/email_address_type.rb +149 -0
  17. data/lib/domainic/type/types/network/hostname_type.rb +107 -0
  18. data/lib/domainic/type/types/network/uri_type.rb +224 -0
  19. data/sig/domainic/type/behavior/string_behavior/matching_behavior.rbs +84 -0
  20. data/sig/domainic/type/behavior/string_behavior.rbs +2 -82
  21. data/sig/domainic/type/behavior/uri_behavior.rbs +95 -0
  22. data/sig/domainic/type/behavior.rbs +9 -0
  23. data/sig/domainic/type/definitions.rbs +149 -1
  24. data/sig/domainic/type/types/identifier/cuid_type.rbs +110 -0
  25. data/sig/domainic/type/types/identifier/uuid_type.rbs +469 -0
  26. data/sig/domainic/type/types/network/email_address_type.rbs +127 -0
  27. data/sig/domainic/type/types/network/hostname_type.rbs +76 -0
  28. data/sig/domainic/type/types/network/uri_type.rbs +159 -0
  29. metadata +20 -6
@@ -0,0 +1,159 @@
1
+ module Domainic
2
+ module Type
3
+ # A type for validating URIs according to RFC 3986 standards
4
+ #
5
+ # This type provides comprehensive URI validation, ensuring that values conform to
6
+ # standard URI syntax. It supports constraints on components like the scheme, hostname,
7
+ # path, and query string.
8
+ #
9
+ # Key features:
10
+ # - RFC-compliant URI validation
11
+ # - Scheme, hostname, path, and query validation
12
+ # - Maximum length enforcement
13
+ # - ASCII character set requirement
14
+ #
15
+ # @example Basic usage
16
+ # type = UriType.new
17
+ # type.validate("https://example.com/path?query=1") # => true
18
+ # type.validate("not-a-uri") # => false
19
+ #
20
+ # @example With scheme constraints
21
+ # type = UriType.new
22
+ # .having_scheme("http", "https")
23
+ #
24
+ # @example With hostname and path constraints
25
+ # type = UriType.new
26
+ # .having_hostname("example.com")
27
+ # .matching_path(/^\/[a-z]+$/)
28
+ #
29
+ # @example With maximum length
30
+ # type = UriType.new
31
+ # .having_maximum_size(2000)
32
+ #
33
+ # @author {https://aaronmallen.me Aaron Allen}
34
+ # @since 0.1.0
35
+ class URIType
36
+ extend Behavior::ClassMethods
37
+
38
+ include Behavior
39
+
40
+ include Behavior::StringBehavior::MatchingBehavior
41
+
42
+ include Behavior::SizableBehavior
43
+
44
+ include Behavior::URIBehavior
45
+
46
+ URI_REGEXP: Regexp
47
+
48
+ # Constrain URI hostname to allowed values
49
+ #
50
+ # Uses `HostnameType` to validate the hostname part of the URI.
51
+ #
52
+ # @example
53
+ # type.having_hostname("example.com")
54
+ # type.validate("https://example.com") # => true
55
+ # type.validate("https://other.com") # => false
56
+ #
57
+ # @param hostnames [Array<String>] List of allowed hostnames
58
+ # @return [self] self for method chaining
59
+ def having_hostname: (*String hostnames) -> self
60
+
61
+ alias allowing_hostname having_hostname
62
+
63
+ alias host having_hostname
64
+
65
+ alias hostname having_hostname
66
+
67
+ alias with_hostname having_hostname
68
+
69
+ # Constrain URI path to match any of the specified patterns
70
+ #
71
+ # Ensures that the path part of the URI matches at least one of the given patterns.
72
+ #
73
+ # @example
74
+ # type.having_path(/^\/[a-z]+$/, /^\/api\/v\d+/)
75
+ # type.validate("https://example.com/path") # => true
76
+ # type.validate("https://example.com/api/v1") # => true
77
+ # type.validate("https://example.com/123") # => false
78
+ #
79
+ # @param patterns [Array<Regexp>] Patterns the path must match
80
+ # @return [self] self for method chaining
81
+ def having_path: (*String | Regexp patterns) -> self
82
+
83
+ alias allowing_path having_path
84
+
85
+ alias with_path having_path
86
+
87
+ # Constrain URI scheme to specific values
88
+ #
89
+ # Ensures that the scheme part of the URI matches one of the specified schemes.
90
+ #
91
+ # @example
92
+ # type.having_scheme("http", "https")
93
+ # type.validate("https://example.com") # => true
94
+ # type.validate("ftp://example.com") # => false
95
+ #
96
+ # @param schemes [Array<String>] List of allowed schemes
97
+ # @return [self] self for method chaining
98
+ def having_scheme: (*String schemes) -> self
99
+
100
+ alias allowing_scheme having_scheme
101
+
102
+ alias scheme having_scheme
103
+
104
+ # Constrain URI hostname to exclude specific values
105
+ #
106
+ # Uses `HostnameType` to blacklist hostnames.
107
+ #
108
+ # @example
109
+ # type.not_having_hostname("forbidden.com")
110
+ # type.validate("https://allowed.com") # => true
111
+ # type.validate("https://forbidden.com") # => false
112
+ #
113
+ # @param hostnames [Array<String>] List of forbidden hostnames
114
+ # @return [self] self for method chaining
115
+ def not_having_hostname: (*String hostnames) -> self
116
+
117
+ alias forbidding_hostname not_having_hostname
118
+
119
+ alias not_host not_having_hostname
120
+
121
+ alias not_hostname not_having_hostname
122
+
123
+ # Constrain URI path to exclude any of the specified patterns
124
+ #
125
+ # Ensures that the path part of the URI does not match any of the given patterns.
126
+ #
127
+ # @example
128
+ # type.not_having_path(/^\/admin/, /^\/private/)
129
+ # type.validate("https://example.com/user") # => true
130
+ # type.validate("https://example.com/admin") # => false
131
+ # type.validate("https://example.com/private") # => false
132
+ #
133
+ # @param patterns [Array<Regexp>] Patterns the path must not match
134
+ # @return [self] self for method chaining
135
+ def not_having_path: (*String | Regexp patterns) -> self
136
+
137
+ alias forbidding_path not_having_path
138
+
139
+ alias not_allowing_path not_having_path
140
+
141
+ # Constrain URI scheme to exclude specific values
142
+ #
143
+ # Ensures that the scheme part of the URI does not match the specified schemes.
144
+ #
145
+ # @example
146
+ # type.not_having_scheme("ftp")
147
+ # type.validate("https://example.com") # => true
148
+ # type.validate("ftp://example.com") # => false
149
+ #
150
+ # @param schemes [Array<String>] List of forbidden schemes
151
+ # @return [self] self for method chaining
152
+ def not_having_scheme: (*String schemes) -> self
153
+
154
+ alias forbidding_scheme not_having_scheme
155
+
156
+ alias not_allowing_scheme not_having_scheme
157
+ end
158
+ end
159
+ 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.0.2
4
+ version: 0.1.0.alpha.3.1.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-25 00:00:00.000000000 Z
11
+ date: 2024-12-26 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
@@ -32,6 +32,8 @@ files:
32
32
  - lib/domainic/type/behavior/numeric_behavior.rb
33
33
  - lib/domainic/type/behavior/sizable_behavior.rb
34
34
  - lib/domainic/type/behavior/string_behavior.rb
35
+ - lib/domainic/type/behavior/string_behavior/matching_behavior.rb
36
+ - lib/domainic/type/behavior/uri_behavior.rb
35
37
  - lib/domainic/type/config/registry.yml
36
38
  - lib/domainic/type/constraint/behavior.rb
37
39
  - lib/domainic/type/constraint/constraints/all_constraint.rb
@@ -67,6 +69,11 @@ files:
67
69
  - lib/domainic/type/types/core/integer_type.rb
68
70
  - lib/domainic/type/types/core/string_type.rb
69
71
  - lib/domainic/type/types/core/symbol_type.rb
72
+ - lib/domainic/type/types/identifier/cuid_type.rb
73
+ - lib/domainic/type/types/identifier/uuid_type.rb
74
+ - lib/domainic/type/types/network/email_address_type.rb
75
+ - lib/domainic/type/types/network/hostname_type.rb
76
+ - lib/domainic/type/types/network/uri_type.rb
70
77
  - lib/domainic/type/types/specialized/instance_type.rb
71
78
  - lib/domainic/type/types/specification/anything_type.rb
72
79
  - lib/domainic/type/types/specification/duck_type.rb
@@ -81,6 +88,8 @@ files:
81
88
  - sig/domainic/type/behavior/numeric_behavior.rbs
82
89
  - sig/domainic/type/behavior/sizable_behavior.rbs
83
90
  - sig/domainic/type/behavior/string_behavior.rbs
91
+ - sig/domainic/type/behavior/string_behavior/matching_behavior.rbs
92
+ - sig/domainic/type/behavior/uri_behavior.rbs
84
93
  - sig/domainic/type/constraint/behavior.rbs
85
94
  - sig/domainic/type/constraint/constraints/all_constraint.rbs
86
95
  - sig/domainic/type/constraint/constraints/and_constraint.rbs
@@ -115,6 +124,11 @@ files:
115
124
  - sig/domainic/type/types/core/integer_type.rbs
116
125
  - sig/domainic/type/types/core/string_type.rbs
117
126
  - sig/domainic/type/types/core/symbol_type.rbs
127
+ - sig/domainic/type/types/identifier/cuid_type.rbs
128
+ - sig/domainic/type/types/identifier/uuid_type.rbs
129
+ - sig/domainic/type/types/network/email_address_type.rbs
130
+ - sig/domainic/type/types/network/hostname_type.rbs
131
+ - sig/domainic/type/types/network/uri_type.rbs
118
132
  - sig/domainic/type/types/specialized/instance_type.rbs
119
133
  - sig/domainic/type/types/specification/anything_type.rbs
120
134
  - sig/domainic/type/types/specification/duck_type.rbs
@@ -122,15 +136,15 @@ files:
122
136
  - sig/domainic/type/types/specification/union_type.rbs
123
137
  - sig/domainic/type/types/specification/void_type.rbs
124
138
  - sig/manifest.yaml
125
- homepage: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.0.2/domainic-type
139
+ homepage: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.1.0/domainic-type
126
140
  licenses:
127
141
  - MIT
128
142
  metadata:
129
143
  bug_tracker_uri: https://github.com/domainic/domainic/issues
130
- changelog_uri: https://github.com/domainic/domainic/releases/tag/domainic-type-v0.1.0-alpha.3.0.2
131
- homepage_uri: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.0.2/domainic-type
144
+ changelog_uri: https://github.com/domainic/domainic/releases/tag/domainic-type-v0.1.0-alpha.3.1.0
145
+ homepage_uri: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.1.0/domainic-type
132
146
  rubygems_mfa_required: 'true'
133
- source_code_uri: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.0.2/domainic-type
147
+ source_code_uri: https://github.com/domainic/domainic/tree/domainic-type-v0.1.0-alpha.3.1.0/domainic-type
134
148
  post_install_message:
135
149
  rdoc_options: []
136
150
  require_paths: