class BloodContracts::Core::ContractFailure
Refinement type which represents invalid data
Public Class Methods
new(value = nil, **)
click to toggle source
Constructs a ContractsFailure using the given value (for ContractFailure
value is an error)
@return [ContractFailure]
Calls superclass method
# File lib/blood_contracts/core/contract_failure.rb, line 9 def initialize(value = nil, **) super @match = self return unless @value @context[:errors] = (@context[:errors].to_a << @value.to_h) end
Public Instance Methods
errors()
click to toggle source
List of errors per type after the data matching process
@return [Array<Hash<BC::Refined, String>>]
# File lib/blood_contracts/core/contract_failure.rb, line 31 def errors @context[:errors].to_a end
errors_h()
click to toggle source
Merged map of errors per type after the data matching process
@return [Hash<BC::Refined, String>]
# File lib/blood_contracts/core/contract_failure.rb, line 47 def errors_h errors.reduce(:merge) end
Also aliased as: to_h
match()
click to toggle source
The type which is the result of validation (for ContractFailure
is always self)
@return [BC::Refined]
# File lib/blood_contracts/core/contract_failure.rb, line 57 def match self end
merge!(contract_failure)
click to toggle source
Merge errors with the errors of another ContractFailure
@param contract_failure [ContractFailure] other errors container which to
merge with
@return [ContractFailure]
# File lib/blood_contracts/core/contract_failure.rb, line 22 def merge!(contract_failure) @context[:errors] = @context[:errors].to_a + contract_failure.errors self end
messages()
click to toggle source
Flatten list of error messages
@return [Array<String>]
# File lib/blood_contracts/core/contract_failure.rb, line 39 def messages errors.reduce(:merge).values.flatten! end