Class: Yes::Core::Aggregate::Dsl::ClassResolvers::ReadModelSerializer

Inherits:
Base
  • Object
show all
Defined in:
lib/yes/core/aggregate/dsl/class_resolvers/read_model_serializer.rb

Overview

Creates and registers read model serializer classes for aggregates

This class resolver generates JSON:API compliant serializer classes for read models. Each serializer class is automatically configured with the specified attributes and type naming conventions.

Examples:

Generated read model serializer class structure

class UserSerializer < Yes::Core::Serializer
  set_type 'users'
  attributes :id, :email, :first_name, :last_name
end

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(read_model_name, context_name, aggregate_name, read_model_attributes) ⇒ ReadModelSerializer

Initializes a new read model serializer class resolver

Parameters:

  • read_model_name (String)

    The name of the read model

  • context_name (String)

    The name of the context

  • aggregate_name (String)

    The name of the aggregate

  • read_model_attributes (Array<Symbol>)

    The attributes to be serialized

Since:

  • 0.1.0



26
27
28
29
30
31
# File 'lib/yes/core/aggregate/dsl/class_resolvers/read_model_serializer.rb', line 26

def initialize(read_model_name, context_name, aggregate_name, read_model_attributes)
  @read_model_name = read_model_name
  @read_model_attributes = read_model_attributes

  super(context_name, aggregate_name)
end

Instance Method Details

#callClass

Creates and registers the read model serializer class in the Yes::Core configuration

Returns:

  • (Class)

    The found or generated read model serializer class that was registered

Since:

  • 0.1.0



36
37
38
39
40
41
42
# File 'lib/yes/core/aggregate/dsl/class_resolvers/read_model_serializer.rb', line 36

def call
  Yes::Core.configuration.register_read_model_filter_class(
    context_name,
    aggregate_name,
    find_or_generate_class
  )
end