Module: Domainic::Attributer::ClassMethods
- Defined in:
- lib/domainic/attributer/class_methods.rb
Overview
A module providing class-level methods for attribute definition.
This module extends classes that include Domainic::Attributer with methods for defining and managing attributes. It supports two types of attributes:
-
Arguments - Positional parameters that must be provided in a specific order
-
Options - Named parameters that can be provided in any order
Instance Method Summary collapse
-
#argument(attribute_name, type_validator = Undefined, **options) {|DSL::AttributeBuilder| ... } ⇒ void
Define a positional argument attribute.
-
#option(attribute_name, type_validator = Undefined, **options, &block) ⇒ void
Define a named option attribute.
Instance Method Details
#argument(attribute_name, type_validator = Undefined, **options) {|DSL::AttributeBuilder| ... } ⇒ void
This method returns an undefined value.
Define a positional argument attribute.
Arguments are required by default and must be provided in the order they are defined. They can be type-validated and configured with additional options like defaults and visibility.
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/domainic/attributer/class_methods.rb', line 119 def argument(attribute_name, type_validator = Undefined, **, &) position = __attributes__.count { |_, attribute| attribute.signature.argument? } attribute = DSL::AttributeBuilder.new( self, attribute_name, :argument, type_validator, **.merge(position:), & ).build! __attributes__.add(attribute) DSL::MethodInjector.inject!(self, attribute) end |
#option(attribute_name, type_validator = Undefined, **options, &block) ⇒ void
This method returns an undefined value.
Define a named option attribute.
Options are optional by default and can be provided in any order. They can be type-validated and configured with additional options like defaults and visibility.
216 217 218 219 220 221 |
# File 'lib/domainic/attributer/class_methods.rb', line 216 def option(attribute_name, ...) attribute = DSL::AttributeBuilder.new(self, attribute_name, :option, ...).build! # steep:ignore __attributes__.add(attribute) DSL::MethodInjector.inject!(self, attribute) end |