class Amber::Schema::LegacyResult

Overview

Legacy Result class for backward compatibility This maintains the existing API while using the new Result types internally

Defined in:

amber/schema/result.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(success : Bool, data : Hash(String, JSON::Any) | Nil = nil, original_data : Hash(String, JSON::Any) | Nil = nil) #

[View source]

Class Method Detail

def self.failure(errors : Array(Error), original_data : Hash(String, JSON::Any) | Nil = nil) #

[View source]
def self.success(data : Hash(String, JSON::Any)) #

Factory methods for creating results


[View source]

Instance Method Detail

def add_error(error : Error) #

Add an error to the result


[View source]
def add_warning(warning : Warning) #

Add a warning (non-fatal issue)


[View source]
def data : Hash(String, JSON::Any) | Nil #

Validated and transformed data


[View source]
def error_messages : Array(String) #

Get all error messages as strings


[View source]
def errors : Array(Error) #

[View source]
def errors_by_field : Hash(String, Array(Error)) #

Get errors grouped by field


[View source]
def failure? #

[View source]
def original_data : Hash(String, JSON::Any) | Nil #

Original input data (for debugging)


[View source]
def success : Bool #

Status of the validation/parsing operation


[View source]
def success? : Bool #

Check if validation/parsing was successful


[View source]
def to_h #

Convert result to a hash suitable for JSON response


[View source]
def to_typed_result : Success(Hash(String, JSON::Any)) | Failure(Hash(String, JSON::Any)) #

Convert to new Result type - only works for types that can be constructed from Hash


[View source]
def warnings : Array(Warning) #

[View source]