Class: Olyx::Guardrails::Notifier
- Inherits:
-
Object
- Object
- Olyx::Guardrails::Notifier
- Defined in:
- lib/olyx/guardrails/notifier.rb
Overview
Dispatches one sanitized guardrail event to named application callables.
Handlers run synchronously and independently; applications can enqueue asynchronous work from a handler. Every handler receives the same deeply frozen event.
Instance Method Summary collapse
-
#initialize(policy:, handlers:) ⇒ Notifier
constructor
:call-seq: Notifier.new(policy:, handlers:) -> Notifier.
-
#notify(result, input: nil, metadata: {}) ⇒ Object
:call-seq: notifier.notify(result, input: nil, metadata: {}) -> Hash or nil.
Constructor Details
#initialize(policy:, handlers:) ⇒ Notifier
:call-seq:
Notifier.new(policy:, handlers:) -> Notifier
Builds a notifier using policy for restricted-content and secret
sanitization. handlers must be a non-empty Hash of one to twenty named
callables. Each callable accepts one immutable event Hash.
Invalid policy, handler names, handler counts, or non-callable handlers raise ArgumentError.
27 28 29 |
# File 'lib/olyx/guardrails/notifier.rb', line 27 def initialize(policy:, handlers:) @policy, @dispatcher = Notification::NotifierSetup.call(policy, handlers) end |
Instance Method Details
#notify(result, input: nil, metadata: {}) ⇒ Object
:call-seq:
notifier.notify(result, input: nil, metadata: {}) -> Hash or nil
Dispatches one sanitized event when result is a decision Hash with a
positive :risk_score. Returns nil for a valid zero-risk decision.
input optionally supplies source text for a bounded, redacted preview.
metadata supplies bounded caller context and must be a Hash.
Invalid decision or metadata arguments raise ArgumentError.
Handler failures are isolated and returned in the delivery summary. Event-building failures are returned without raising. See docs/OPERATIONS.md#notification-delivery for both result shapes.
45 46 47 48 49 50 |
# File 'lib/olyx/guardrails/notifier.rb', line 45 def notify(result, input: nil, metadata: {}) validate_arguments!(result, ) return nil if result[:risk_score].zero? deliver(result, input, ) end |