Module: EzLogsAgent::ActorValidator

Defined in:
lib/ez_logs_agent/actor_validator.rb

Overview

Validates and sanitizes actor data structures.

Actor schema:

id: String,               # REQUIRED, stable identifier
label: String | nil       # optional, human-readable display

This module ensures actors conform to the expected structure before being stored in event context.

Class Method Summary collapse

Class Method Details

.sanitize(actor) ⇒ Hash?

Sanitize actor structure to ensure consistent format Returns nil for invalid actors

Parameters:

  • actor (Hash, nil)

    Actor hash to sanitize

Returns:

  • (Hash, nil)

    Sanitized actor or nil



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ez_logs_agent/actor_validator.rb', line 37

def sanitize(actor)
  return nil unless valid?(actor)
  return nil if actor.nil?

  id = actor[:id] || actor["id"]
  label = actor[:label] || actor["label"]

  result = { id: id.to_s }
  result[:label] = label.to_s if label

  result
end

.valid?(actor) ⇒ Boolean

Check if an actor structure is valid

Parameters:

  • actor (Hash, nil)

    Actor hash to validate

Returns:

  • (Boolean)

    true if valid (including nil), false otherwise



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ez_logs_agent/actor_validator.rb', line 19

def valid?(actor)
  # nil actor is valid (means "unknown provenance")
  return true if actor.nil?

  # Must be a Hash
  return false unless actor.is_a?(Hash)

  # id is required
  id = actor[:id] || actor["id"]
  return false if id.nil? || id.to_s.empty?

  true
end