Class: Riffer::Guardrails::Tripwire
- Inherits:
-
Object
- Object
- Riffer::Guardrails::Tripwire
- Defined in:
- lib/riffer/guardrails/tripwire.rb,
sig/generated/riffer/guardrails/tripwire.rbs
Overview
Captures information about a blocked guardrail execution.
Constant Summary collapse
- PHASES =
: Array
Riffer::Guardrails::PHASES
Instance Attribute Summary collapse
-
#guardrail ⇒ singleton(Riffer::Guardrail)
readonly
The guardrail class that triggered the block.
-
#metadata ⇒ Hash[Symbol, untyped]?
readonly
Optional metadata about the block.
-
#phase ⇒ Symbol
readonly
The phase when the block occurred (:before or :after).
-
#reason ⇒ String
readonly
The reason for blocking.
Instance Method Summary collapse
-
#initialize(reason:, guardrail:, phase:, metadata: nil) ⇒ Tripwire
constructor
Raises Riffer::ArgumentError if
phaseis invalid. -
#to_h ⇒ Hash[Symbol, untyped]
Converts the tripwire to a hash.
Constructor Details
#initialize(reason:, guardrail:, phase:, metadata: nil) ⇒ Tripwire
Raises Riffer::ArgumentError if phase is invalid.
: (reason: String, guardrail: singleton(Riffer::Guardrail), phase: Symbol, ?metadata: Hash[Symbol, untyped]?) -> void
23 24 25 26 27 28 29 30 |
# File 'lib/riffer/guardrails/tripwire.rb', line 23 def initialize(reason:, guardrail:, phase:, metadata: nil) raise Riffer::ArgumentError, "Invalid phase: #{phase}" unless PHASES.include?(phase) @reason = reason @guardrail = guardrail @phase = phase @metadata = end |
Instance Attribute Details
#guardrail ⇒ singleton(Riffer::Guardrail) (readonly)
The guardrail class that triggered the block.
12 13 14 |
# File 'lib/riffer/guardrails/tripwire.rb', line 12 def guardrail @guardrail end |
#metadata ⇒ Hash[Symbol, untyped]? (readonly)
Optional metadata about the block.
18 19 20 |
# File 'lib/riffer/guardrails/tripwire.rb', line 18 def @metadata end |
#phase ⇒ Symbol (readonly)
The phase when the block occurred (:before or :after).
15 16 17 |
# File 'lib/riffer/guardrails/tripwire.rb', line 15 def phase @phase end |
#reason ⇒ String (readonly)
The reason for blocking.
9 10 11 |
# File 'lib/riffer/guardrails/tripwire.rb', line 9 def reason @reason end |
Instance Method Details
#to_h ⇒ Hash[Symbol, untyped]
Converts the tripwire to a hash.
-- : () -> Hash[Symbol, untyped]
36 37 38 39 40 41 42 43 |
# File 'lib/riffer/guardrails/tripwire.rb', line 36 def to_h { reason: reason, guardrail: guardrail.name, phase: phase, metadata: } end |