Sha256: 09f44dc68804d1bdde6a9ce8105f7db9a85d0fdf14c46c0acf91256f656127b7

Contents?: true

Size: 773 Bytes

Versions: 2

Compression:

Stored size: 773 Bytes

Contents

module BloodContracts::Core
  # Represents failure in Tuple data matching
  class TupleContractFailure < ContractFailure
    # Hash of attributes (name & type pairs)
    #
    # @return [Hash<String, Refined>]
    #
    def attributes
      @context[:attributes]
    end

    # Subset of attributes which are invalid
    #
    # @return [Hash<String, ContractFailure>]
    #
    def attribute_errors
      attributes.select { |_name, type| type.invalid? }
    end

    # Unpacked matching errors in form of a hash per attribute
    #
    # @return [Hash<String, ContractFailure>]
    #
    def unpack_h
      @unpack_h ||= attribute_errors.transform_values(&:unpack)
    end
    alias to_hash unpack_h
    alias to_h unpack_h
    alias unpack_attributes unpack_h
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
blood_contracts-core-0.4.2 lib/blood_contracts/core/tuple_contract_failure.rb
blood_contracts-core-0.4.1 lib/blood_contracts/core/tuple_contract_failure.rb