Sha256: 2406e49feff5a728a23f1d034cdfb64ff06196986c15d7a2d5f9fa46e0695988
Contents?: true
Size: 1.64 KB
Versions: 1
Compression:
Stored size: 1.64 KB
Contents
module BloodContracts::Core module Ext # Refinement type exteneded with Extractable, ExceptionHandling and # errors representation in form of Tram::Policy::Errors class Refined < ::BC::Refined # Adds ability to generate custom errors in form of Tram::Policy::Errors extend DefineableError.new(:contracts) # Adds extractors DSL include Extractable # Adds exception handling in form of refinment type prepend ExceptionHandling # Sets the default failure_klass to PolicyFailure, to use # Tram::Policy::Errors for errors self.failure_klass = PolicyFailure class << self # Compose types in a Sum check # Sum passes data from type to type in parallel, only one type # have to match # # @return [BC::Sum] # def or_a(other_type) BC::Ext::Sum.new(self, other_type) end # Compose types in a Pipe check # Pipe passes data from type to type sequentially # # @return [BC::Pipe] # def and_then(other_type) BC::Ext::Pipe.new(self, other_type) end # @private def inherited(new_klass) new_klass.failure_klass ||= failure_klass new_klass.prepend ExceptionHandling super end end # Generate an PolicyFailure from the error, also stores the # additional scope for Tram::Policy::Errors in the context # # @param (see BC::Refined#failure) # @return [PolicyFailure] # def failure(*, **) @context[:sub_scope] = self.class.name super end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
blood_contracts-ext-0.1.0 | lib/blood_contracts/ext/refined.rb |