domainic-attributer 0.1.0 → 0.2.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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +11 -0
  3. data/CHANGELOG.md +32 -1
  4. data/README.md +42 -355
  5. data/docs/USAGE.md +723 -0
  6. data/lib/domainic/attributer/attribute/callback.rb +21 -9
  7. data/lib/domainic/attributer/attribute/coercer.rb +28 -13
  8. data/lib/domainic/attributer/attribute/mixin/belongs_to_attribute.rb +16 -13
  9. data/lib/domainic/attributer/attribute/signature.rb +43 -32
  10. data/lib/domainic/attributer/attribute/validator.rb +46 -16
  11. data/lib/domainic/attributer/attribute.rb +28 -18
  12. data/lib/domainic/attributer/attribute_set.rb +21 -19
  13. data/lib/domainic/attributer/class_methods.rb +136 -83
  14. data/lib/domainic/attributer/dsl/attribute_builder/option_parser.rb +64 -22
  15. data/lib/domainic/attributer/dsl/attribute_builder.rb +515 -26
  16. data/lib/domainic/attributer/dsl/initializer.rb +23 -18
  17. data/lib/domainic/attributer/dsl/method_injector.rb +16 -14
  18. data/lib/domainic/attributer/errors/aggregate_error.rb +36 -0
  19. data/lib/domainic/attributer/errors/callback_execution_error.rb +30 -0
  20. data/lib/domainic/attributer/errors/coercion_execution_error.rb +37 -0
  21. data/lib/domainic/attributer/errors/error.rb +19 -0
  22. data/lib/domainic/attributer/errors/validation_execution_error.rb +30 -0
  23. data/lib/domainic/attributer/instance_methods.rb +11 -8
  24. data/lib/domainic/attributer/undefined.rb +9 -7
  25. data/lib/domainic/attributer.rb +88 -27
  26. data/sig/domainic/attributer/attribute/callback.rbs +10 -7
  27. data/sig/domainic/attributer/attribute/coercer.rbs +14 -11
  28. data/sig/domainic/attributer/attribute/mixin/belongs_to_attribute.rbs +14 -12
  29. data/sig/domainic/attributer/attribute/signature.rbs +43 -32
  30. data/sig/domainic/attributer/attribute/validator.rbs +28 -13
  31. data/sig/domainic/attributer/attribute.rbs +27 -17
  32. data/sig/domainic/attributer/attribute_set.rbs +21 -19
  33. data/sig/domainic/attributer/class_methods.rbs +133 -80
  34. data/sig/domainic/attributer/dsl/attribute_builder/option_parser.rbs +62 -22
  35. data/sig/domainic/attributer/dsl/attribute_builder.rbs +515 -26
  36. data/sig/domainic/attributer/dsl/initializer.rbs +21 -19
  37. data/sig/domainic/attributer/dsl/method_injector.rbs +16 -14
  38. data/sig/domainic/attributer/errors/aggregate_error.rbs +28 -0
  39. data/sig/domainic/attributer/errors/callback_execution_error.rbs +23 -0
  40. data/sig/domainic/attributer/errors/coercion_execution_error.rbs +29 -0
  41. data/sig/domainic/attributer/errors/error.rbs +17 -0
  42. data/sig/domainic/attributer/errors/validation_execution_error.rbs +23 -0
  43. data/sig/domainic/attributer/instance_methods.rbs +11 -8
  44. data/sig/domainic/attributer/undefined.rbs +5 -3
  45. data/sig/domainic/attributer.rbs +88 -27
  46. metadata +19 -6
@@ -1,13 +1,15 @@
1
1
  module Domainic
2
2
  module Attributer
3
- # A class representing an ordered collection of attributes.
3
+ # A class responsible for managing an ordered collection of attributes
4
4
  #
5
5
  # This class manages a set of attributes for a given class or module. It maintains
6
6
  # attributes in a specific order determined by their type (argument vs option),
7
7
  # default values, and position. The collection supports standard operations like
8
8
  # adding, selecting, and merging attributes while maintaining proper ownership
9
- # relationships with their base class.
9
+ # relationships with their base class
10
10
  #
11
+ # @api private
12
+ # @!visibility private
11
13
  # @author {https://aaronmallen.me Aaron Allen}
12
14
  # @since 0.1.0
13
15
  class AttributeSet
@@ -17,61 +19,61 @@ module Domainic
17
19
 
18
20
  @lookup: Hash[Symbol, Attribute]
19
21
 
20
- # Initialize a new AttributeSet.
22
+ # Initialize a new AttributeSet
21
23
  #
22
24
  # @param base [Class, Module] the class or module this set belongs to
23
25
  # @param attributes [Array<Attribute>] initial attributes to add
24
26
  #
25
- # @return [void]
27
+ # @return [AttributeSet] the new AttributeSet instance
26
28
  def initialize: (__todo__ base, ?Array[Attribute] attributes) -> void
27
29
 
28
- # Get an attribute by name.
30
+ # Get an attribute by name
29
31
  #
30
32
  # @param attribute_name [String, Symbol] the name of the attribute
31
33
  #
32
34
  # @return [Attribute, nil] the attribute if found
33
35
  def []: (String | Symbol attribute_name) -> Attribute?
34
36
 
35
- # Add an attribute to the set.
37
+ # Add an attribute to the set
36
38
  #
37
39
  # If an attribute with the same name exists, the attributes are merged.
38
40
  # If the attribute belongs to a different base class, it is duplicated
39
41
  # with the correct base. After adding, attributes are sorted by type
40
- # and position.
42
+ # and position
41
43
  #
42
44
  # @param attribute [Attribute] the attribute to add
43
45
  #
44
- # @raise [ArgumentError] if attribute is invalid
46
+ # @raise [ArgumentError] if attribute is not a valid {Attribute}
45
47
  # @return [void]
46
48
  def add: (Attribute attribute) -> void
47
49
 
48
- # Check if an attribute exists in the set.
50
+ # Check if an attribute exists in the set
49
51
  #
50
52
  # @param attribute_name [String, Symbol] the name to check
51
53
  #
52
54
  # @return [Boolean] true if the attribute exists
53
55
  def attribute?: (untyped attribute_name) -> untyped
54
56
 
55
- # Get all attribute names.
57
+ # Get all attribute names
56
58
  #
57
59
  # @return [Array<Symbol>] the attribute names
58
60
  def attribute_names: () -> Array[Symbol]
59
61
 
60
- # Get all attributes.
62
+ # Get all attributes
61
63
  #
62
64
  # @return [Array<Attribute>] the attributes
63
65
  def attributes: () -> Array[Attribute]
64
66
 
65
67
  def count: () ?{ (Symbol, Attribute) -> boolish } -> Integer
66
68
 
67
- # Create a duplicate set for a new base class.
69
+ # Create a duplicate set for a new base class
68
70
  #
69
71
  # @param new_base [Class, Module] the new base class
70
72
  #
71
73
  # @return [AttributeSet] the duplicated set
72
74
  def dup_with_base: (__todo__ base) -> AttributeSet
73
75
 
74
- # Iterate over attribute name/value pairs.
76
+ # Iterate over attribute name/value pairs
75
77
  #
76
78
  # @yield [name, attribute] each name/attribute pair
77
79
  # @yieldparam name [Symbol] the attribute name
@@ -84,7 +86,7 @@ module Domainic
84
86
 
85
87
  def empty?: () -> bool
86
88
 
87
- # Create a new set excluding specified attributes.
89
+ # Create a new set excluding specified attributes
88
90
  #
89
91
  # @param attribute_names [Array<String, Symbol>] names to exclude
90
92
  #
@@ -93,14 +95,14 @@ module Domainic
93
95
 
94
96
  def length: () -> Integer
95
97
 
96
- # Merge another set into this one.
98
+ # Merge another set into this one
97
99
  #
98
100
  # @param other [AttributeSet] the set to merge
99
101
  #
100
102
  # @return [AttributeSet] new set with merged attributes
101
103
  def merge: (AttributeSet other) -> AttributeSet
102
104
 
103
- # Create a new set with rejected attributes.
105
+ # Create a new set with rejected attributes
104
106
  #
105
107
  # @yield [name, attribute] each name/attribute pair
106
108
  # @yieldparam name [Symbol] the attribute name
@@ -109,7 +111,7 @@ module Domainic
109
111
  # @return [AttributeSet] new set without rejected attributes
110
112
  def reject: () { (Symbol, Attribute) -> boolish } -> AttributeSet
111
113
 
112
- # Create a new set with selected attributes.
114
+ # Create a new set with selected attributes
113
115
  #
114
116
  # @yield [name, attribute] each name/attribute pair
115
117
  # @yieldparam name [Symbol] the attribute name
@@ -122,10 +124,10 @@ module Domainic
122
124
 
123
125
  private
124
126
 
125
- # Sort attributes by type and position.
127
+ # Sort attributes by type and position
126
128
  #
127
129
  # Attributes are sorted first by type (required arguments, defaulted arguments,
128
- # then options), and then by their position within those groups.
130
+ # then options), and then by their position within those groups
129
131
  #
130
132
  # @return [void]
131
133
  def sort_lookup: () -> void
@@ -1,94 +1,150 @@
1
1
  module Domainic
2
2
  module Attributer
3
- # A module providing class-level methods for attribute definition.
4
- #
5
- # This module extends classes that include Domainic::Attributer with methods for
6
- # defining and managing attributes. It supports two types of attributes:
3
+ # This module extends classes that include {Domainic::Attributer} with methods for defining and managing attributes.
4
+ # It supports two types of attributes:
7
5
  # 1. Arguments - Positional parameters that must be provided in a specific order
8
6
  # 2. Options - Named parameters that can be provided in any order
9
7
  #
8
+ # @note This module is automatically extended when {Domainic::Attributer} is included in a class
9
+ #
10
10
  # @example Defining arguments and options
11
11
  # class Person
12
12
  # include Domainic::Attributer
13
13
  #
14
- # argument :name, ->(value) { value.is_a?(String) }
15
- # argument :age do |value|
16
- # value.is_a?(Integer) && value >= 0
14
+ # argument :name, String
15
+ # argument :age, Integer do
16
+ # validate_with ->(val) { val >= 0 }
17
17
  # end
18
18
  #
19
- # option :email, ->(value) { value.is_a?(String) }, default: nil
20
- # option :role do |value|
21
- # %w[admin user guest].include?(value)
19
+ # option :email, String, default: nil
20
+ # option :role do
21
+ # validate_with ->(val) { %w[admin user guest].include?(val) }
22
22
  # end
23
23
  # end
24
24
  #
25
+ # person = Person.new('Alice', 30, email: 'alice123@gmail.com', role: 'user')
26
+ # # => #<Person:0x0000000104bc5f98 @age=30, @email="alice123@gmail.com", @name="Alice", @role="user">
27
+ #
25
28
  # @author {https://aaronmallen.me Aaron Allen}
26
29
  # @since 0.1.0
27
30
  module ClassMethods
28
31
  @__attributes__: AttributeSet
29
32
 
30
- # Define a positional argument attribute.
31
- #
32
- # Arguments are required by default and must be provided in the order they are defined.
33
- # They can be type-validated and configured with additional options like defaults
34
- # and visibility.
35
- #
36
- # @param attribute_name [String, Symbol] the name of the attribute
37
- # @param type_validator [Proc, Object, nil] optional validation handler for type checking
38
- # @param options [Hash] additional configuration options
39
- #
40
- # @option options [Array<Proc>, Proc] :callbacks handlers for attribute change events (priority over :callback,
41
- # :on_change)
42
- # @option options [Array<Proc>, Proc] :callback alias for :callbacks
43
- # @option options [Array<Proc, Symbol>, Proc, Symbol] :coerce handlers for value coercion (priority over
44
- # :coercers, :coerce_with)
45
- # @option options [Array<Proc, Symbol>, Proc, Symbol] :coercers alias for :coerce
46
- # @option options [Array<Proc, Symbol>, Proc, Symbol] :coerce_with alias for :coerce
47
- # @option options [Object] :default the default value (priority over :default_generator, :default_value)
48
- # @option options [Object] :default_generator alias for :default
49
- # @option options [Object] :default_value alias for :default
50
- # @option options [String] :desc short description (overridden by :description)
51
- # @option options [String] :description description text
52
- # @option options [Boolean] :non_nil require non-nil values (priority over :non_null, :non_nullable, :not_nil,
53
- # :not_nilable, :not_null, :not_nullable)
54
- # @option options [Boolean] :non_null alias for :non_nil
55
- # @option options [Boolean] :non_nullable alias for :non_nil
56
- # @option options [Boolean] :not_nil alias for :non_nil
57
- # @option options [Boolean] :not_nilable alias for :non_nil
58
- # @option options [Boolean] :not_null alias for :non_nil
59
- # @option options [Boolean] :not_nullable alias for :non_nil
60
- # @option options [Boolean] :null inverse of :non_nil
61
- # @option options [Array<Proc>, Proc] :on_change alias for :callbacks
62
- # @option options [Boolean] :optional whether attribute is optional (overridden by :required)
63
- # @option options [Integer] :position specify order position
64
- # @option options [Symbol] :read read visibility (:public, :protected, :private) (priority over :read_access,
65
- # :reader)
66
- # @option options [Symbol] :read_access alias for :read
67
- # @option options [Symbol] :reader alias for :read
68
- # @option options [Boolean] :required whether attribute is required
69
- # @option options [Array<Object>, Object] :validate validators for the attribute (priority over :validate_with,
70
- # :validators)
71
- # @option options [Array<Object>, Object] :validate_with alias for :validate
72
- # @option options [Array<Object>, Object] :validators alias for :validate
73
- # @option options [Symbol] :write_access write visibility (:public, :protected, :private) (priority over :writer)
74
- # @option options [Symbol] :writer alias for :write_access
75
- #
76
- # @yield [DSL::AttributeBuilder] optional configuration block
77
- # @return [void]
33
+ # Define a positional argument attribute
34
+ #
35
+ # Arguments are required by default and must be provided in the order they are defined unless they have a default
36
+ # value. They can be type-validated and configured with additional options like defaults and visibility
37
+ #
38
+ # @see DSL::AttributeBuilder
39
+ #
40
+ # @example Using the options API
41
+ # class Person
42
+ # argument :name, String
43
+ # argument :age, ->(val) { val.is_a?(Integer) && val >= 0 }
44
+ # argument :role, default: 'user'
45
+ # end
46
+ #
47
+ # @example Using the block API
48
+ # class Person
49
+ # argument :name, String do
50
+ # validate_with ->(val) { val.length >= 3 }
51
+ # end
52
+ #
53
+ # argument :age, Integer do
54
+ # coerce_with ->(val) { val.to_i }
55
+ # validate_with ->(val) { val >= 0 }
56
+ # end
57
+ #
58
+ # argument :role, String do
59
+ # validate_with ->(val) { VALID_USER_ROLES.include?(val) }
60
+ # default 'user'
61
+ # end
62
+ # end
63
+ #
64
+ # @overload argument(attribute_name, type_validator = nil, **options)
65
+ # @param attribute_name [String, Symbol] the name of the attribute
66
+ # @param type_validator [Proc, Object, nil] optional validation handler for type checking
67
+ # @param options [Hash{Symbol => Object}] additional configuration options
68
+ # @option options [Array<Proc>, Proc] :callbacks handlers for attribute change events (priority over
69
+ # :callback, :on_change)
70
+ # @option options [Array<Proc>, Proc] :callback alias for :callbacks
71
+ # @option options [Array<Proc, Symbol>, Proc, Symbol] :coerce handlers for value coercion (priority over
72
+ # :coercers, :coerce_with)
73
+ # @option options [Array<Proc, Symbol>, Proc, Symbol] :coercers alias for :coerce
74
+ # @option options [Array<Proc, Symbol>, Proc, Symbol] :coerce_with alias for :coerce
75
+ # @option options [Object] :default the default value (priority over :default_generator, :default_value)
76
+ # @option options [Object] :default_generator alias for :default
77
+ # @option options [Object] :default_value alias for :default
78
+ # @option options [String] :desc short description (overridden by :description)
79
+ # @option options [String] :description description text
80
+ # @option options [Boolean] :non_nil require non-nil values (priority over :non_null, :non_nullable, :not_nil,
81
+ # :not_nilable, :not_null, :not_nullable)
82
+ # @option options [Boolean] :non_null alias for :non_nil
83
+ # @option options [Boolean] :non_nullable alias for :non_nil
84
+ # @option options [Boolean] :not_nil alias for :non_nil
85
+ # @option options [Boolean] :not_nilable alias for :non_nil
86
+ # @option options [Boolean] :not_null alias for :non_nil
87
+ # @option options [Boolean] :not_nullable alias for :non_nil
88
+ # @option options [Boolean] :null inverse of :non_nil
89
+ # @option options [Array<Proc>, Proc] :on_change alias for :callbacks
90
+ # @option options [Boolean] :optional whether attribute is optional (overridden by :required)
91
+ # @option options [Integer] :position specify order position
92
+ # @option options [Symbol] :read read visibility (:public, :protected, :private) (priority over :read_access,
93
+ # :reader)
94
+ # @option options [Symbol] :read_access alias for :read
95
+ # @option options [Symbol] :reader alias for :read
96
+ # @option options [Boolean] :required whether attribute is required
97
+ # @option options [Array<Object>, Object] :validate validators for the attribute (priority over
98
+ # :validate_with, :validators)
99
+ # @option options [Array<Object>, Object] :validate_with alias for :validate
100
+ # @option options [Array<Object>, Object] :validators alias for :validate
101
+ # @option options [Symbol] :write_access write visibility (:public, :protected, :private) (priority over
102
+ # :writer)
103
+ # @option options [Symbol] :writer alias for :write_access
104
+ #
105
+ # @yield [DSL::AttributeBuilder] configuration block for additional attribute settings
106
+ # @return [void]
78
107
  def argument: (String | Symbol attribute_name, ?Attribute::Validator::handler type_validator, ?callbacks: Array[Attribute::Callback::handler] | Attribute::Callback::handler, ?callback: Array[Attribute::Callback::handler] | Attribute::Callback::handler, ?coerce: Array[Attribute::Coercer::handler] | Attribute::Coercer::handler, ?coercers: Array[Attribute::Coercer::handler], ?coerce_with: [ Attribute::Coercer::handler ] | Attribute::Coercer::handler, ?default: untyped, ?default_generator: untyped, ?default_value: untyped, ?desc: String?, ?description: String, ?non_nil: bool, ?non_null: bool, ?non_nullable: bool, ?not_nil: bool, ?not_nilable: bool, ?not_null: bool, ?not_nullable: bool, ?null: bool, ?on_change: Array[Attribute::Callback::handler] | Attribute::Callback::handler, ?optional: bool, ?position: Integer?, ?read: Attribute::Signature::visibility_symbol, ?read_access: Attribute::Signature::visibility_symbol, ?reader: Attribute::Signature::visibility_symbol, ?required: bool, ?validate: Array[Attribute::Validator::handler] | Attribute::Validator::handler, ?validate_with: Array[Attribute::Validator::handler] | Attribute::Validator::handler, ?validators: Array[Attribute::Validator::handler] | Attribute::Validator::handler, ?write_access: Attribute::Signature::visibility_symbol, ?writer: Attribute::Signature::visibility_symbol) ?{ (?) [self: DSL::AttributeBuilder] -> void } -> void
79
108
 
80
- # Define a named option attribute.
109
+ # Define a named option attribute
81
110
  #
82
111
  # Options are optional by default and can be provided in any order. They can be
83
- # type-validated and configured with additional options like defaults and visibility.
112
+ # type-validated and configured with additional options like defaults and visibility
113
+ #
114
+ # @see DSL::AttributeBuilder
115
+ # @see DSL::AttributeBuilder::OptionParser#initialize
84
116
  #
85
- # @overload option(attribute_name, type_validator = Undefined, **options, &block)
117
+ # @example Using the options API
118
+ # class Person
119
+ # option :email, String
120
+ # option :age, ->(val) { val.is_a?(Integer) && val >= 0 }
121
+ # option :role, default: 'user'
122
+ # end
123
+ #
124
+ # @example Using the block API
125
+ # class Person
126
+ # option :email, String do
127
+ # coerce_with ->(val) { val.downcase }
128
+ # validate_with ->(val) { URI::MailTo::EMAIL_REGEXP.match?(val) }
129
+ # end
130
+ #
131
+ # option :age, Integer do
132
+ # coerce_with ->(val) { val.to_i }
133
+ # validate_with ->(val) { val >= 0 }
134
+ # end
135
+ #
136
+ # option :role, String do
137
+ # validate_with ->(val) { VALID_USER_ROLES.include?(val) }
138
+ # default 'user'
139
+ # end
140
+ # end
141
+ #
142
+ # @overload option(attribute_name, type_validator = nil, **options)
86
143
  # @param attribute_name [String, Symbol] the name of the attribute
87
144
  # @param type_validator [Proc, Object, nil] optional validation handler for type checking
88
- # @param options [Hash] additional configuration options
89
- #
90
- # @option options [Array<Proc>, Proc] :callbacks handlers for attribute change events (priority over :callback,
91
- # :on_change)
145
+ # @param options [Hash{Symbol => Object}] additional configuration options
146
+ # @option options [Array<Proc>, Proc] :callbacks handlers for attribute change events (priority over
147
+ # :callback, :on_change)
92
148
  # @option options [Array<Proc>, Proc] :callback alias for :callbacks
93
149
  # @option options [Array<Proc, Symbol>, Proc, Symbol] :coerce handlers for value coercion (priority over
94
150
  # :coercers, :coerce_with)
@@ -116,36 +172,33 @@ module Domainic
116
172
  # @option options [Symbol] :read_access alias for :read
117
173
  # @option options [Symbol] :reader alias for :read
118
174
  # @option options [Boolean] :required whether attribute is required
119
- # @option options [Array<Object>, Object] :validate validators for the attribute (priority over :validate_with,
120
- # :validators)
175
+ # @option options [Array<Object>, Object] :validate validators for the attribute (priority over
176
+ # :validate_with, :validators)
121
177
  # @option options [Array<Object>, Object] :validate_with alias for :validate
122
178
  # @option options [Array<Object>, Object] :validators alias for :validate
123
- # @option options [Symbol] :write_access write visibility (:public, :protected, :private)
124
- # (priority over :writer)
179
+ # @option options [Symbol] :write_access write visibility (:public, :protected, :private) (priority over
180
+ # :writer)
125
181
  # @option options [Symbol] :writer alias for :write_access
126
182
  #
127
- # @yield [DSL::AttributeBuilder] optional configuration block
128
- # @return [void]
129
- #
130
- # @yield [DSL::AttributeBuilder] optional configuration block
183
+ # @yield [DSL::AttributeBuilder] configuration block for additional attribute settings
131
184
  # @return [void]
132
185
  def option: (String | Symbol attribute_name, ?Attribute::Validator::handler type_validator, ?callbacks: Array[Attribute::Callback::handler] | Attribute::Callback::handler, ?callback: Array[Attribute::Callback::handler] | Attribute::Callback::handler, ?coerce: Array[Attribute::Coercer::handler] | Attribute::Coercer::handler, ?coercers: Array[Attribute::Coercer::handler], ?coerce_with: [ Attribute::Coercer::handler ] | Attribute::Coercer::handler, ?default: untyped, ?default_generator: untyped, ?default_value: untyped, ?desc: String?, ?description: String, ?non_nil: bool, ?non_null: bool, ?non_nullable: bool, ?not_nil: bool, ?not_nilable: bool, ?not_null: bool, ?not_nullable: bool, ?null: bool, ?on_change: Array[Attribute::Callback::handler] | Attribute::Callback::handler, ?optional: bool, ?position: Integer?, ?read: Attribute::Signature::visibility_symbol, ?read_access: Attribute::Signature::visibility_symbol, ?reader: Attribute::Signature::visibility_symbol, ?required: bool, ?validate: Array[Attribute::Validator::handler] | Attribute::Validator::handler, ?validate_with: Array[Attribute::Validator::handler] | Attribute::Validator::handler, ?validators: Array[Attribute::Validator::handler] | Attribute::Validator::handler, ?write_access: Attribute::Signature::visibility_symbol, ?writer: Attribute::Signature::visibility_symbol) ?{ (?) [self: DSL::AttributeBuilder] -> void } -> void
133
186
 
134
187
  private
135
188
 
136
- # Handle class inheritance for attributes.
189
+ # Get the attribute set for this class
190
+ #
191
+ # @return [AttributeSet] the set of attributes defined for this class
192
+ def __attributes__: () -> AttributeSet
193
+
194
+ # Handle class inheritance for attributes
137
195
  #
138
196
  # Ensures that subclasses inherit a copy of their parent's attributes while
139
- # maintaining proper ownership relationships.
197
+ # maintaining proper ownership relationships
140
198
  #
141
199
  # @param subclass [Class] the inheriting class
142
200
  # @return [void]
143
201
  def inherited: (Class | Module subclass) -> void
144
-
145
- # Get the attribute set for this class.
146
- #
147
- # @return [AttributeSet] the set of attributes defined for this class
148
- def __attributes__: () -> AttributeSet
149
202
  end
150
203
  end
151
204
  end
@@ -2,12 +2,15 @@ module Domainic
2
2
  module Attributer
3
3
  module DSL
4
4
  class AttributeBuilder
5
- # A class responsible for parsing and normalizing attribute options.
5
+ # A class responsible for parsing and normalizing attribute options
6
6
  #
7
7
  # This class handles the conversion of flexible DSL options into a normalized
8
8
  # format for attribute creation. It supports multiple ways of specifying common
9
9
  # options (like visibility, nullability, validation) and consolidates them
10
- # into a consistent internal representation.
10
+ # into a consistent internal representation
11
+ #
12
+ # @!visibility private
13
+ # @api private
11
14
  #
12
15
  # @author {https://aaronmallen.me Aaron Allen}
13
16
  # @since 0.1.0
@@ -47,79 +50,116 @@ module Domainic
47
50
 
48
51
  @options: options
49
52
 
50
- # Parse attribute options into a normalized format.
53
+ # Parse attribute options into a normalized format
51
54
  #
52
55
  # @param attribute_name [String, Symbol] the name of the attribute
53
56
  # @param attribute_type [String, Symbol] the type of attribute
54
- # @param options [Hash] the options to parse
57
+ # @param options [Hash{String, Symbol => Object}] the options to parse. See {#initialize} for details.
55
58
  #
56
- # @return [Hash] normalized options suitable for attribute creation
59
+ # @return [Hash{Symbol => Object}] normalized options suitable for attribute creation
57
60
  def self.parse!: (String | Symbol attribute_name, String | Symbol attribute_type, options options) -> void
58
61
 
59
- # Initialize a new OptionParser.
62
+ # Initialize a new OptionParser instance
60
63
  #
61
64
  # @param attribute_name [String, Symbol] the name of the attribute
62
65
  # @param attribute_type [String, Symbol] the type of attribute
63
- # @param options [Hash] the options to parse
64
- #
65
- # @return [void]
66
+ # @param options [Hash{String, Symbol => Object}] the options to parse
67
+ #
68
+ # @option options [Array<Proc>, Proc] :callbacks handlers for attribute change events (priority over
69
+ # :callback, :on_change)
70
+ # @option options [Array<Proc>, Proc] :callback alias for :callbacks
71
+ # @option options [Array<Proc, Symbol>, Proc, Symbol] :coerce handlers for value coercion (priority over
72
+ # :coercers, :coerce_with)
73
+ # @option options [Array<Proc, Symbol>, Proc, Symbol] :coercers alias for :coerce
74
+ # @option options [Array<Proc, Symbol>, Proc, Symbol] :coerce_with alias for :coerce
75
+ # @option options [Object] :default the default value (priority over :default_generator, :default_value)
76
+ # @option options [Object] :default_generator alias for :default
77
+ # @option options [Object] :default_value alias for :default
78
+ # @option options [String] :desc short description (overridden by :description)
79
+ # @option options [String] :description description text
80
+ # @option options [Boolean] :non_nil require non-nil values (priority over :non_null, :non_nullable, :not_nil,
81
+ # :not_nilable, :not_null, :not_nullable)
82
+ # @option options [Boolean] :non_null alias for :non_nil
83
+ # @option options [Boolean] :non_nullable alias for :non_nil
84
+ # @option options [Boolean] :not_nil alias for :non_nil
85
+ # @option options [Boolean] :not_nilable alias for :non_nil
86
+ # @option options [Boolean] :not_null alias for :non_nil
87
+ # @option options [Boolean] :not_nullable alias for :non_nil
88
+ # @option options [Boolean] :null inverse of :non_nil
89
+ # @option options [Array<Proc>, Proc] :on_change alias for :callbacks
90
+ # @option options [Boolean] :optional whether attribute is optional (overridden by :required)
91
+ # @option options [Integer] :position specify order position
92
+ # @option options [Symbol] :read read visibility (:public, :protected, :private) (priority over :read_access,
93
+ # :reader)
94
+ # @option options [Symbol] :read_access alias for :read
95
+ # @option options [Symbol] :reader alias for :read
96
+ # @option options [Boolean] :required whether attribute is required
97
+ # @option options [Array<Object>, Object] :validate validators for the attribute (priority over
98
+ # :validate_with, :validators)
99
+ # @option options [Array<Object>, Object] :validate_with alias for :validate
100
+ # @option options [Array<Object>, Object] :validators alias for :validate
101
+ # @option options [Symbol] :write_access write visibility (:public, :protected, :private) (priority over
102
+ # :writer)
103
+ # @option options [Symbol] :writer alias for :write_access
104
+ #
105
+ # @return [OptionParser] the new OptionParser instance
66
106
  def initialize: (String | Symbol attribute_name, String | Symbol attribute_type, options options) -> void
67
107
 
68
- # Parse the options into a normalized format.
108
+ # Parse the options into a normalized format
69
109
  #
70
- # @return [Hash] normalized options suitable for attribute creation
110
+ # @return [Hash{Symbol => Object}] normalized options suitable for attribute creation
71
111
  def parse!: () -> result
72
112
 
73
113
  private
74
114
 
75
- # Find the last set value among multiple option keys.
115
+ # Find the last set value among multiple option keys
76
116
  #
77
117
  # @param keys [Array<Symbol>] the keys to check
78
118
  #
79
- # @return [Object] the last set value or Undefined
119
+ # @return [Object] the last set value or {Undefined}
80
120
  def find_last_option: (Array[Symbol]) -> untyped
81
121
 
82
- # Parse accessor (reader/writer) visibility options.
122
+ # Parse accessor (reader/writer) visibility options
83
123
  #
84
124
  # @return [void]
85
125
  def parse_accessor_options!: () -> void
86
126
 
87
- # Parse callback handler options.
127
+ # Parse callback handler options
88
128
  #
89
129
  # @return [void]
90
130
  def parse_callbacks_options!: () -> void
91
131
 
92
- # Parse coercion handler options.
132
+ # Parse coercion handler options
93
133
  #
94
134
  # @return [void]
95
135
  def parse_coercers_options!: () -> void
96
136
 
97
- # Parse default value options.
137
+ # Parse default value options
98
138
  #
99
139
  # @return [void]
100
140
  def parse_default_options!: () -> void
101
141
 
102
- # Parse description options.
142
+ # Parse description options
103
143
  #
104
144
  # @return [void]
105
145
  def parse_description_options!: () -> void
106
146
 
107
- # Parse nilability options.
147
+ # Parse nilability options
108
148
  #
109
149
  # @return [void]
110
150
  def parse_nilable_options!: () -> void
111
151
 
112
- # Parse all option types.
152
+ # Parse all option types
113
153
  #
114
154
  # @return [void]
115
155
  def parse_options!: () -> void
116
156
 
117
- # Parse required/optional options.
157
+ # Parse required/optional options
118
158
  #
119
159
  # @return [void]
120
160
  def parse_required_options!: () -> void
121
161
 
122
- # Parse validator options.
162
+ # Parse validator options
123
163
  #
124
164
  # @return [void]
125
165
  def parse_validator_options!: () -> void