Module: Domainic::Attributer::ClassMethods
- Defined in:
- lib/domainic/attributer/class_methods.rb
Overview
Note:
This module is automatically extended when Domainic::Attributer is included in a class
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 = nil, **options) {|DSL::AttributeBuilder| ... } ⇒ void
Define a positional argument attribute.
-
#option(attribute_name, type_validator = nil, **options) {|DSL::AttributeBuilder| ... } ⇒ void
Define a named option attribute.
Instance Method Details
#argument(attribute_name, type_validator = nil, **options) {|DSL::AttributeBuilder| ... } ⇒ void
Define a positional argument attribute
Arguments are required by default and must be provided in the order they are defined unless they have a default value. They can be type-validated and configured with additional options like defaults and visibility
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/domainic/attributer/class_methods.rb', line 148 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 = nil, **options) {|DSL::AttributeBuilder| ... } ⇒ void
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
269 270 271 272 273 274 |
# File 'lib/domainic/attributer/class_methods.rb', line 269 def option(attribute_name, ...) attribute = DSL::AttributeBuilder.new(self, attribute_name, :option, ...).build! # steep:ignore __attributes__.add(attribute) DSL::MethodInjector.inject!(self, attribute) end |