Module: Treaty::Attribute::DSL::ClassMethods

Defined in:
lib/treaty/attribute/dsl.rb

Instance Method Summary collapse

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

Parameters:

  • type (Symbol)

    The attribute type (method name)

  • name (Symbol)

    The attribute name (first argument)

  • helpers (Array<Symbol>)

    Helper symbols

  • options (Hash)

    Attribute options

  • block (Proc)

    Block for nested attributes



60
61
62
63
64
65
66
67
68
# File 'lib/treaty/attribute/dsl.rb', line 60

def method_missing(type, *helpers, **options, &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, **options, &block)
end

Instance Method Details

#attribute(name, type, *helpers, **options, &block) ⇒ void

This method returns an undefined value.

Defines an attribute with explicit type

Parameters:

  • name (Symbol)

    The attribute name

  • type (Symbol)

    The attribute type

  • helpers (Array<Symbol>)

    Helper symbols (:required, :optional)

  • options (Hash)

    Attribute options

  • block (Proc)

    Block for nested attributes



34
35
36
37
38
39
40
41
42
43
# File 'lib/treaty/attribute/dsl.rb', line 34

def attribute(name, type, *helpers, **options, &block)
  collection_of_attributes << create_attribute(
    name,
    type,
    *helpers,
    nesting_level: 0,
    **options,
    &block
  )
end

#collection_of_attributesCollection

Returns collection of attributes for this class

Returns:



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

Returns:

  • (Boolean)


70
71
72
# File 'lib/treaty/attribute/dsl.rb', line 70

def respond_to_missing?(name, *)
  super
end