Module: Castkit::DataObjectExtensions::AttributeTypes
- Included in:
- Castkit::DataObject
- Defined in:
- lib/castkit/data_object_extensions/attribute_types.rb
Overview
Provides DSL methods to define typed attributes in a Castkit::DataObject.
These helpers are shortcuts for calling ‘attribute` with a specific type.
Instance Method Summary collapse
-
#array(field, **options) ⇒ Object
(also: #collection)
Defines an array attribute.
-
#boolean(field, **options) ⇒ Object
Defines a boolean attribute.
-
#dataobject(field, type, **options) ⇒ Object
(also: #object, #dto)
Defines a nested Castkit::DataObject attribute.
-
#date(field, **options) ⇒ Object
Defines a date attribute.
-
#datetime(field, **options) ⇒ Object
Defines a datetime attribute.
-
#float(field, **options) ⇒ Object
Defines a float attribute.
-
#hash(field, **options) ⇒ Object
Defines a hash attribute.
-
#integer(field, **options) ⇒ Object
Defines an integer attribute.
-
#string(field, **options) ⇒ Object
Defines a string attribute.
-
#unwrapped(field, type, **options) ⇒ Object
Defines an unwrapped nested Castkit::DataObject attribute.
Instance Method Details
#array(field, **options) ⇒ Object Also known as: collection
Defines an array attribute.
61 62 63 |
# File 'lib/castkit/data_object_extensions/attribute_types.rb', line 61 def array(field, **) attribute(field, :array, **) end |
#boolean(field, **options) ⇒ Object
Defines a boolean attribute.
29 30 31 |
# File 'lib/castkit/data_object_extensions/attribute_types.rb', line 29 def boolean(field, **) attribute(field, :boolean, **) end |
#dataobject(field, type, **options) ⇒ Object Also known as: object, dto
Defines a nested Castkit::DataObject attribute.
79 80 81 82 83 84 85 |
# File 'lib/castkit/data_object_extensions/attribute_types.rb', line 79 def dataobject(field, type, **) unless type < Castkit::DataObject raise Castkit::AttributeError, "Data objects must extend from Castkit::DataObject" end attribute(field, type, **) end |
#date(field, **options) ⇒ Object
Defines a date attribute.
45 46 47 |
# File 'lib/castkit/data_object_extensions/attribute_types.rb', line 45 def date(field, **) attribute(field, :date, **) end |
#datetime(field, **options) ⇒ Object
Defines a datetime attribute.
53 54 55 |
# File 'lib/castkit/data_object_extensions/attribute_types.rb', line 53 def datetime(field, **) attribute(field, :datetime, **) end |
#float(field, **options) ⇒ Object
Defines a float attribute.
37 38 39 |
# File 'lib/castkit/data_object_extensions/attribute_types.rb', line 37 def float(field, **) attribute(field, :float, **) end |
#hash(field, **options) ⇒ Object
Defines a hash attribute.
69 70 71 |
# File 'lib/castkit/data_object_extensions/attribute_types.rb', line 69 def hash(field, **) attribute(field, :hash, **) end |
#integer(field, **options) ⇒ Object
Defines an integer attribute.
21 22 23 |
# File 'lib/castkit/data_object_extensions/attribute_types.rb', line 21 def integer(field, **) attribute(field, :integer, **) end |
#string(field, **options) ⇒ Object
Defines a string attribute.
13 14 15 |
# File 'lib/castkit/data_object_extensions/attribute_types.rb', line 13 def string(field, **) attribute(field, :string, **) end |
#unwrapped(field, type, **options) ⇒ Object
Defines an unwrapped nested Castkit::DataObject attribute.
All keys from this object will be flattened with an optional prefix.
94 95 96 |
# File 'lib/castkit/data_object_extensions/attribute_types.rb', line 94 def unwrapped(field, type, **) attribute(field, type, **, unwrapped: true) end |