Class: Yes::Core::Aggregate::Dsl::ClassResolvers::ReadModel

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

Overview

Creates and registers read model classes for aggregates

This class resolver generates ActiveRecord-based read model classes that represent the queryable state of aggregates. Each read model class is automatically configured with basic scopes and table name conventions.

Examples:

Generated read model class structure

class User < ApplicationRecord
  self.table_name = 'users'
  scope :by_ids, ->(ids) { where(id: ids) }
end

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(read_model_name, context_name, aggregate_name, draft: false) ⇒ ReadModel

Initializes a new read model 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

Since:

  • 0.1.0



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

def initialize(read_model_name, context_name, aggregate_name, draft: false)
  @read_model_name = read_model_name
  @draft = draft

  super(context_name, aggregate_name)
end

Instance Method Details

#callClass

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

Returns:

  • (Class)

    The found or generated read model class that was registered

Since:

  • 0.1.0



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

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