Module: Treaty::Attribute::DSL::ClassMethods
- Defined in:
- lib/treaty/attribute/dsl.rb
Instance Method Summary collapse
-
#attribute(name, type, *helpers, **options, &block) ⇒ void
Defines an attribute with explicit type.
-
#collection_of_attributes ⇒ Collection
Returns collection of attributes for this class.
-
#method_missing(type, *helpers, **options, &block) ⇒ void
Handles DSL methods like ‘string :name` where method name is the type.
- #respond_to_missing?(name) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(type, *helpers, **options, &block) ⇒ void
This method returns an undefined value.
Handles DSL methods like ‘string :name` where method name is the type
60 61 62 63 64 65 66 67 68 |
# File 'lib/treaty/attribute/dsl.rb', line 60 def method_missing(type, *helpers, **, &block) name = helpers.shift # If no attribute name provided, this is not an attribute definition # Pass to super to handle it properly (e.g., for methods like 'info', 'call!', etc.) return super if name.nil? attribute(name, type, *helpers, **, &block) end |
Instance Method Details
#attribute(name, type, *helpers, **options, &block) ⇒ void
This method returns an undefined value.
Defines an attribute with explicit type
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/treaty/attribute/dsl.rb', line 34 def attribute(name, type, *helpers, **, &block) collection_of_attributes << create_attribute( name, type, *helpers, nesting_level: 0, **, &block ) end |
#collection_of_attributes ⇒ Collection
Returns collection of attributes for this class
48 49 50 |
# File 'lib/treaty/attribute/dsl.rb', line 48 def collection_of_attributes @collection_of_attributes ||= Treaty::Attribute::Collection.new end |
#respond_to_missing?(name) ⇒ Boolean
70 71 72 |
# File 'lib/treaty/attribute/dsl.rb', line 70 def respond_to_missing?(name, *) super end |