Class: Omnes::PublicationContext

Inherits:
Object
  • Object
show all
Defined in:
lib/omnes/publication_context.rb

Overview

Context for an event publication

An instance of this class is shared between all the executions that are triggered by the publication of a given event. It's provided to the subscriptions as their second argument when they take it.

This class is useful mainly for debugging and logging purposes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(caller_location:, time:) ⇒ PublicationContext

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of PublicationContext.



26
27
28
29
# File 'lib/omnes/publication_context.rb', line 26

def initialize(caller_location:, time:)
  @caller_location = caller_location
  @time = time
end

Instance Attribute Details

#caller_locationThread::Backtrace::Location (readonly)

Location for the event publisher

It's set by Bus#publish, and it points to the caller of that method.

Returns:

  • (Thread::Backtrace::Location)


18
19
20
# File 'lib/omnes/publication_context.rb', line 18

def caller_location
  @caller_location
end

#timeTime (readonly)

Time of the event publication

Returns:

  • (Time)


23
24
25
# File 'lib/omnes/publication_context.rb', line 23

def time
  @time
end

Instance Method Details

#serializedObject

Serialized version of a publication context



34
35
36
37
38
39
# File 'lib/omnes/publication_context.rb', line 34

def serialized
  {
    "caller_location" => caller_location.to_s,
    "time" => time.to_s
  }
end