class BloodContracts::Core::PolicyFailure

ContractFailure which holds errors in form of Tram::Policy::Errors

Public Class Methods

new(errors_per_type = nil, context: {}, **) click to toggle source

Builds an PolicyFailure, turns the errors into Tram::Policy::Errors if they are not, yet

@param errors_per_type [Hash<Refined, Array<String,Symbol>>] map of

errors per type, each type could have a list of errors

@option context [Hash] shared context of matching pipeline

Calls superclass method
# File lib/blood_contracts/core/policy_failure.rb, line 15
def initialize(errors_per_type = nil, context: {}, **)
  sub_scope = context.delete(:sub_scope)
  errors_per_type.to_h.transform_values! do |errors|
    errors.map do |error|
      next(error) if error.is_a?(Tram::Policy::Errors)
      self.class.define_error(error, tags: context, sub_scope: sub_scope)
    end
  end
  super
end

Public Instance Methods

messages() click to toggle source

Merged list of Tram::Policy::Errors messages (or their translations)

@return [Array<String>]

# File lib/blood_contracts/core/policy_failure.rb, line 38
def messages
  @messages ||= policy_errors.map(&:messages).flatten
end
policy_errors() click to toggle source

Merged list of Tram::Policy::Errors after the matching run

@return [Array<Tram::Policy::Errors>]

# File lib/blood_contracts/core/policy_failure.rb, line 30
def policy_errors
  @policy_errors ||= @value.values.flatten
end