Sha256: c3bac950bfbd8d762d1da0470e804e5dc01469d9e9801cb396d1550110539c50

Contents?: true

Size: 977 Bytes

Versions: 2

Compression:

Stored size: 977 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

    # Contexts for subset of attributes which are invalid
    #
    # @return [Hash<String, ContractFailure>]
    #
    def attribute_contexts
      attribute_errors.transform_values!(&:context)
    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.4 lib/blood_contracts/core/tuple_contract_failure.rb
blood_contracts-core-0.4.3 lib/blood_contracts/core/tuple_contract_failure.rb