Sha256: 5f092238df22923f5bf1552da47bf274beed5bf360ea759a4276e9ef7145c24f

Contents?: true

Size: 882 Bytes

Versions: 4

Compression:

Stored size: 882 Bytes

Contents

module BloodContracts::Core
  module Ext
    # Refinement types representation of Sum types composition, extended version
    class Tuple < ::BC::Tuple
      # Sets the default failure_klass to PolicyFailure, to use
      # Tram::Policy::Errors for errors
      self.failure_klass = TuplePolicyFailure

      # @private
      def self.inherited(new_klass)
        new_klass.failure_klass ||= failure_klass
        super
      end

      # Generate an PolicyFailure from the error, also stores the
      # additional scope for Tram::Policy::Errors in the context.
      # Also saves the Tuple error in the context[:attributes] by the :base key
      #
      # @param (see BC::Refined#failure)
      # @return [PolicyFailure]
      #
      def failure(*, **)
        @context[:sub_scope] = self.class.name
        @context[:attributes].store(:base, super)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
blood_contracts-ext-0.1.3 lib/blood_contracts/ext/tuple.rb
blood_contracts-ext-0.1.2 lib/blood_contracts/ext/tuple.rb
blood_contracts-ext-0.1.1 lib/blood_contracts/ext/tuple.rb
blood_contracts-ext-0.1.0 lib/blood_contracts/ext/tuple.rb