Module: EzLogsAgent::Actor

Defined in:
lib/ez_logs_agent/actor.rb

Overview

Manages actor context for the current request.

Actor represents “who triggered this action” - the logged-in user.

Actor schema:

id: String,         # REQUIRED - stable identifier (e.g., user.id)
label: String       # optional - human-readable display (e.g., user.email)

Usage:

# Configured via actor_from_request hook in EzLogsAgent.configure

Class Method Summary collapse

Class Method Details

.clearvoid

This method returns an undefined value.

Clear the current actor



50
51
52
53
54
# File 'lib/ez_logs_agent/actor.rb', line 50

def clear
  RequestStore.store[:ez_logs_actor] = nil
rescue => e
  EzLogsAgent::Logger.debug("[Actor] clear failed: #{e.message}")
end

.currentHash?

Get the current actor for this request

Returns:

  • (Hash, nil)

    Current actor or nil if not set



22
23
24
25
26
27
# File 'lib/ez_logs_agent/actor.rb', line 22

def current
  RequestStore.store[:ez_logs_actor]
rescue => e
  EzLogsAgent::Logger.debug("[Actor] current failed: #{e.message}")
  nil
end

.current=(actor) ⇒ Hash?

Set the current actor for this request Validates and sanitizes the actor before storing

Parameters:

  • actor (Hash, nil)

    Actor to set

Returns:

  • (Hash, nil)

    The sanitized actor that was stored



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ez_logs_agent/actor.rb', line 33

def current=(actor)
  validated = ActorValidator.sanitize(actor)

  # Log debug message if actor was invalid (user hook misconfiguration)
  if actor && validated.nil?
    EzLogsAgent::Logger.debug("[Actor] Invalid actor structure ignored: #{actor.inspect}")
  end

  RequestStore.store[:ez_logs_actor] = validated
  validated
rescue => e
  EzLogsAgent::Logger.debug("[Actor] current= failed: #{e.message}")
  nil
end