Sha256: 6bf8029889407a8f12c823ef3d2aa110c620e9ca5045b742f66ff6a43224ad82
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 KB
Contents
# frozen_string_literal: true Dry::Monads::Result::Success.class_eval do alias context success end Dry::Monads::Result::Failure.class_eval do alias context failure end module ClearLogic module Result DEFAULT_ERRORS = %i[ unauthorized forbidden not_found invalid ].freeze private def self.included(base) base.extend(ClassMethdos) base.errors(*DEFAULT_ERRORS) end module ClassMethdos def errors(*errors_methods) errors_methods.each do |error_type| define_method(error_type) do |context| context.failure_error ||= ClearLogic::FailureError.new(error_type) failure(context) end private error_type end end end def success(context) Dry::Monads::Result::Success.new(context) end def exit_success(context) context.exit_success = true success(context) end def failure(context) Dry::Monads::Result::Failure.new(context) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
clear_logic-0.1.1 | lib/clear_logic/result.rb |