Class: Riffer::Guardrails::Modification

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

Overview

Records a guardrail transformation event.

When a guardrail transforms data (via transform), a Modification is created to record which guardrail made the change, in which phase, and which message indices were affected.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(guardrail_id:, phase:, message_indices:) ⇒ Modification

Creates a new modification record.

guardrail_id - identifier of the guardrail that transformed. phase - :before or :after. message_indices - indices of changed messages.

: (guardrail_id: String, phase: Symbol, message_indices: Array) -> void



26
27
28
29
30
# File 'lib/riffer/guardrails/modification.rb', line 26

def initialize(guardrail_id:, phase:, message_indices:)
  @guardrail_id = guardrail_id
  @phase = phase
  @message_indices = message_indices
end

Instance Attribute Details

#guardrail_idObject (readonly)

The identifier of the guardrail that transformed data.



11
12
13
# File 'lib/riffer/guardrails/modification.rb', line 11

def guardrail_id
  @guardrail_id
end

#message_indicesObject (readonly)

The indices of messages that were changed.



17
18
19
# File 'lib/riffer/guardrails/modification.rb', line 17

def message_indices
  @message_indices
end

#phaseObject (readonly)

The phase when the transformation occurred (:before or :after).



14
15
16
# File 'lib/riffer/guardrails/modification.rb', line 14

def phase
  @phase
end

Instance Method Details

#to_hObject

Converts the modification to a hash.

: () -> Hash[Symbol, untyped]



35
36
37
# File 'lib/riffer/guardrails/modification.rb', line 35

def to_h
  {guardrail_id: guardrail_id, phase: phase, message_indices: message_indices}
end