class Riffer::Guardrails::Result
Represents the result of a guardrail execution: pass (continue unchanged), transform (continue with changed data), or block (halt with a reason).
Constants
- TYPES
Attributes
The data (for pass/transform) or reason (for block).
Optional metadata for block results.
The result type (:pass, :transform, or :block).
Public Class Methods
Source
# File lib/riffer/guardrails/result.rb, line 36 def block(reason, metadata: nil) new(:block, reason, metadata: metadata) end
Creates a block result that halts execution.
Source
# File lib/riffer/guardrails/result.rb, line 44 def initialize(type, data, metadata: nil) raise Riffer::ArgumentError, "Invalid result type: #{type}" unless TYPES.include?(type) @type = type @data = data @metadata = metadata end
Raises Riffer::ArgumentError if type is not :pass, :transform, or :block.
Source
# File lib/riffer/guardrails/result.rb, line 22 def pass(data) new(:pass, data) end
Creates a pass result that continues with unchanged data.
Source
# File lib/riffer/guardrails/result.rb, line 29 def transform(data) new(:transform, data) end
Creates a transform result that continues with transformed data.
Public Instance Methods
Source
# File lib/riffer/guardrails/result.rb, line 72 def block? type == :block end
Returns true if this is a block result.
Source
# File lib/riffer/guardrails/result.rb, line 56 def pass? type == :pass end
Returns true if this is a pass result.
Source
# File lib/riffer/guardrails/result.rb, line 64 def transform? type == :transform end
Returns true if this is a transform result.