module Cuprum::Rails::Responders::Serialization

Implements serializing a result value into response data.

Attributes

root_serializer[R]

@return [Object] the root serializer for serializing the result value.

serializers[R]

@return [Hash<Class, Object>] The serializers for converting result values

into serialized data.

Public Class Methods

new(root_serializer:, serializers:, **options) click to toggle source

@param root_serializer [Class] The root serializer for serializing the

result value.

@param serializers [Hash<Class, Object>] The serializers for converting

result values into serialized data.

@param options [Hash] Additional parameters for the responder.

Calls superclass method
# File lib/cuprum/rails/responders/serialization.rb, line 13
def initialize(root_serializer:, serializers:, **options)
  super(**options)

  @root_serializer = root_serializer
  @serializers     = serializers
end

Public Instance Methods

serialize(object) click to toggle source

Converts a result value into a serialized data structure.

@param object [Object] The object to serialize.

@return [Object] the serialized data.

# File lib/cuprum/rails/responders/serialization.rb, line 32
def serialize(object)
  root_serializer.call(object, serializers: serializers)
end