Class: Protege::Orchestrator::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/protege/orchestrator/context.rb

Overview

Base context shared by both kinds of run. Carries the per-run runtime data every tool and resolver needs — persona, a frozen config snapshot, logger, correlation id — plus the #deliver affordance for sending mail through the Gateway, without exposing mutable framework state. Frozen after construction so one instance is safely shared across every tool/resolver invocation in a run.

The thing that drove the run differs by kind, so it is exposed through two accessors that both default to nil here and are each overridden by exactly one subclass: ReplyContext sets #message (reactive, an inbound email) and ResponsibilityContext sets #responsibility (proactive, a scheduled Loop run). Tools and resolvers branch on whichever is present.

Direct Known Subclasses

ReplyContext, ResponsibilityContext

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(persona:) ⇒ void

Capture the shared runtime data and freeze. Subclasses set their own subject ivar before calling super, since this constructor freezes the instance.

Parameters:



27
28
29
30
31
32
33
34
35
36
# File 'lib/protege/orchestrator/context.rb', line 27

def initialize(persona:)
  @persona        = persona
  @logger         = Protege.configuration.logger
  # Snapshot a frozen *copy* so the context is immutable without freezing the process-wide
  # configuration (which boot-time code and tests still mutate).
  @config         = Protege.configuration.dup.freeze
  @correlation_id = Protege::Current.correlation_id

  freeze
end

Instance Attribute Details

#configProtege::Persona, ... (readonly)

Returns:

  • (Protege::Persona)

    the persona handling this run

  • (Protege::Configuration)

    the frozen process configuration snapshot

  • (Logger)

    the engine logger

  • (String, nil)

    the correlation id threaded through this run's events



20
21
22
# File 'lib/protege/orchestrator/context.rb', line 20

def config
  @config
end

#correlation_idProtege::Persona, ... (readonly)

Returns:

  • (Protege::Persona)

    the persona handling this run

  • (Protege::Configuration)

    the frozen process configuration snapshot

  • (Logger)

    the engine logger

  • (String, nil)

    the correlation id threaded through this run's events



20
21
22
# File 'lib/protege/orchestrator/context.rb', line 20

def correlation_id
  @correlation_id
end

#loggerProtege::Persona, ... (readonly)

Returns:

  • (Protege::Persona)

    the persona handling this run

  • (Protege::Configuration)

    the frozen process configuration snapshot

  • (Logger)

    the engine logger

  • (String, nil)

    the correlation id threaded through this run's events



20
21
22
# File 'lib/protege/orchestrator/context.rb', line 20

def logger
  @logger
end

#personaProtege::Persona, ... (readonly)

Returns:

  • (Protege::Persona)

    the persona handling this run

  • (Protege::Configuration)

    the frozen process configuration snapshot

  • (Logger)

    the engine logger

  • (String, nil)

    the correlation id threaded through this run's events



20
21
22
# File 'lib/protege/orchestrator/context.rb', line 20

def persona
  @persona
end

Instance Method Details

#deliver(mail:, attachments: []) ⇒ Object

Deliver an outbound mail via the Gateway, handling transport, thread resolution, and message persistence under the current persona. Any attachments (blobs already in storage) are attached to the persisted outbound message by reference, so a file is never re-uploaded on send.

Parameters:

  • mail (Object)

    the outbound mail to deliver

  • attachments (Array<ActiveStorage::Blob>) (defaults to: [])

    blobs to attach to the outbound message

Returns:

  • (Object)

    the Gateway delivery outcome



60
61
62
# File 'lib/protege/orchestrator/context.rb', line 60

def deliver(mail:, attachments: [])
  Gateway.deliver(mail:, persona:, attachments:)
end

#messageObject?

The inbound message that drove this run, or nil when none did (overridden by ReplyContext).

Returns:

  • (Object, nil)


41
42
43
# File 'lib/protege/orchestrator/context.rb', line 41

def message
  nil
end

#responsibilityProtege::Responsibility?

The responsibility that drove this run, or nil when none did (overridden by ResponsibilityContext).

Returns:



49
50
51
# File 'lib/protege/orchestrator/context.rb', line 49

def responsibility
  nil
end