Class: Riffer::Guardrails::Tripwire

Inherits:
Object
  • Object
show all
Defined in:
lib/riffer/guardrails/tripwire.rb

Overview

Captures information about a blocked guardrail execution.

Constant Summary collapse

PHASES =

: Array

Riffer::Guardrails::PHASES

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#guardrailObject (readonly)

The guardrail class that triggered the block.



12
13
14
# File 'lib/riffer/guardrails/tripwire.rb', line 12

def guardrail
  @guardrail
end

#metadataObject (readonly)

Optional metadata about the block.



18
19
20
# File 'lib/riffer/guardrails/tripwire.rb', line 18

def 
  @metadata
end

#phaseObject (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

#reasonObject (readonly)

The reason for blocking.



9
10
11
# File 'lib/riffer/guardrails/tripwire.rb', line 9

def reason
  @reason
end

Instance Method Details

#to_hObject

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