Class: Castkit::DefaultSerializer

Inherits:
Serializer show all
Defined in:
lib/castkit/default_serializer.rb

Overview

Default serializer for Castkit::DataObject instances.

Serializes attributes based on access rules, nil/blank filtering, and nested structure.

Constant Summary collapse

SKIP_ATTRIBUTE =
:__castkit_skip_attribute

Instance Attribute Summary collapse

Attributes inherited from Serializer

#obj

Instance Method Summary collapse

Methods inherited from Serializer

call

Instance Attribute Details

#attributesHash{Symbol => Castkit::Attribute} (readonly)

Returns attributes to serialize.

Returns:



13
14
15
# File 'lib/castkit/default_serializer.rb', line 13

def attributes
  @attributes
end

#optionsHash (readonly)

Returns serialization options (root key, ignore_nil, etc.).

Returns:

  • (Hash)

    serialization options (root key, ignore_nil, etc.)



16
17
18
# File 'lib/castkit/default_serializer.rb', line 16

def options
  @options
end

Instance Method Details

#callHash

Returns the serialized object as a Hash.

Includes root wrapping if configured.

Returns:

  • (Hash)


23
24
25
26
# File 'lib/castkit/default_serializer.rb', line 23

def call
  result = serialize_attributes
  options[:root] ? { options[:root].to_sym => result } : result
end