Class: Yes::Core::Commands::Stateless::Subject

Inherits:
Data
  • Object
show all
Defined in:
lib/yes/core/commands/stateless/subject.rb

Overview

Subject object is responsible for holding subject data

Examples:

Yes::Core::Commands::Stateless::Subject.new(
  context: 'ApprenticeshipPresentation',
  subject: 'Apprenticeship',
  aggregate_id: '123'
)

Constant Summary collapse

OPTIONAL_FIELDS =
%i[stream_prefix].index_with(nil).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attrs) ⇒ Subject

Returns a new instance of Subject.



23
24
25
# File 'lib/yes/core/commands/stateless/subject.rb', line 23

def initialize(**attrs)
  super(**OPTIONAL_FIELDS.merge(attrs))
end

Instance Attribute Details

#aggregate_idString (readonly)

Returns the current value of aggregate_id.

Returns:

  • (String)

    the current value of aggregate_id



20
21
22
# File 'lib/yes/core/commands/stateless/subject.rb', line 20

def aggregate_id
  @aggregate_id
end

#contextString (readonly)

Returns the current value of context.

Returns:

  • (String)

    the current value of context



20
21
22
# File 'lib/yes/core/commands/stateless/subject.rb', line 20

def context
  @context
end

#stream_prefixString (readonly)

value is optional

Returns:

  • (String)

    the current value of stream_prefix



20
21
22
# File 'lib/yes/core/commands/stateless/subject.rb', line 20

def stream_prefix
  @stream_prefix
end

#subjectString (readonly)

Returns the current value of subject.

Returns:

  • (String)

    the current value of subject



20
21
22
# File 'lib/yes/core/commands/stateless/subject.rb', line 20

def subject
  @subject
end

Instance Method Details

#computed_stream_prefixString

Returns:

  • (String)


34
35
36
# File 'lib/yes/core/commands/stateless/subject.rb', line 34

def computed_stream_prefix
  stream_prefix || "#{context}::#{subject}"
end

#streamPgEventstore::Stream

Returns:

  • (PgEventstore::Stream)


28
29
30
31
# File 'lib/yes/core/commands/stateless/subject.rb', line 28

def stream
  parts = computed_stream_prefix.split('::')
  PgEventstore::Stream.new(context: parts[0], stream_name: parts[1..].join('::'), stream_id: aggregate_id)
end