Module: Castkit::DSL::DataObject

Included in:
Castkit::DataObject
Defined in:
lib/castkit/dsl/data_object.rb,
lib/castkit/dsl/data_object/plugins.rb,
lib/castkit/dsl/data_object/contract.rb,
lib/castkit/dsl/data_object/introspection.rb,
lib/castkit/dsl/data_object/serialization.rb,
lib/castkit/dsl/data_object/deserialization.rb

Overview

Provides the complete DSL used by Castkit data objects.

This module can be included into any class to make it behave like a ‘Castkit::DataObject` without requiring subclassing. It wires in the full attribute DSL, type system, contract support, plugin lifecycle, and (de)serialization logic.

This is what powers ‘Castkit::DataObject` internally, and is intended for advanced use cases where composition is preferred over inheritance.

When included, this module:

Examples:

Including in a custom data object

class MyObject
  include Castkit::DSL::DataObject

  string :id
  boolean :active, default: true
end

See Also:

Defined Under Namespace

Modules: Contract, Deserialization, Introspection, Plugins, Serialization

Class Method Summary collapse

Class Method Details

.included(base) ⇒ void

This method returns an undefined value.

Hook triggered when the module is included.

Parameters:

  • base (Class)

    the including class



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/castkit/dsl/data_object.rb', line 50

def self.included(base)
  base.include(Cattri)

  base.extend(Castkit::Core::Config)
  base.extend(Castkit::Core::Attributes)
  base.extend(Castkit::Core::AttributeTypes)
  base.extend(Castkit::DSL::DataObject::Contract)
  base.extend(Castkit::DSL::DataObject::Plugins)
  base.extend(Castkit::DSL::DataObject::Introspection)

  base.include(Castkit::DSL::DataObject::Serialization)
  base.include(Castkit::DSL::DataObject::Deserialization)
end