class Riffer::Guardrails::Result
Represents the result of a guardrail execution.
Results can be one of three types: - pass: Continue with the original data unchanged - transform: Continue with transformed data - block: Halt execution with a reason
Use the factory methods to create results: Result.pass(data) Result.transform(data) Result.block(reason, metadata: nil)
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 52 def block(reason, metadata: nil) new(:block, reason, metadata: metadata) end
Creates a block result that halts execution.
+reason+ - the reason for blocking. +metadata+ - optional additional information.
: (String, ?metadata: Hash[Symbol, untyped]?) -> Riffer::Guardrails::Result
Source
# File lib/riffer/guardrails/result.rb, line 66 def initialize(type, data, metadata: nil) raise Riffer::ArgumentError, "Invalid result type: #{type}" unless TYPES.include?(type) @type = type @data = data @metadata = metadata end
Creates a new result.
+type+ - the result type (:pass, :transform, or :block). +data+ - the data or reason. +metadata+ - optional metadata for block results.
Raises Riffer::ArgumentError if the result type is invalid.
: (Symbol, untyped, ?metadata: Hash[Symbol, untyped]?) -> void
Source
# File lib/riffer/guardrails/result.rb, line 33 def pass(data) new(:pass, data) end
Creates a pass result that continues with unchanged data.
+data+ - the original data to pass through.
: (untyped) -> Riffer::Guardrails::Result
Source
# File lib/riffer/guardrails/result.rb, line 42 def transform(data) new(:transform, data) end
Creates a transform result that continues with transformed data.
+data+ - the transformed data.
: (untyped) -> Riffer::Guardrails::Result
Public Instance Methods
Source
# File lib/riffer/guardrails/result.rb, line 91 def block? type == :block end
Returns true if this is a block result.
: () -> bool
Source
# File lib/riffer/guardrails/result.rb, line 77 def pass? type == :pass end
Returns true if this is a pass result.
: () -> bool
Source
# File lib/riffer/guardrails/result.rb, line 84 def transform? type == :transform end
Returns true if this is a transform result.
: () -> bool