Sha256: f243d739cc12621696640f7a79b4076fe17086ff066addcbae19dcd31ad03495

Contents?: true

Size: 850 Bytes

Versions: 2

Compression:

Stored size: 850 Bytes

Contents

# typed: strict
# frozen_string_literal: true

require 'dry/monads/all'
require 'clean_architecture/entities/failure_details'

module CleanArchitecture
  module Checks
    class Authorization
      extend T::Sig
      extend T::Helpers

      abstract!

      sig { returns(Dry::Monads::Result[Entities::FailureDetails, NilClass]) }
      def result
        if authorized?
          Dry::Monads::Success(nil)
        else
          failure_details = Entities::FailureDetails.new(
            message: failure_message,
            type: Entities::FailureType::Unauthorized
          )
          Dry::Monads::Failure(failure_details)
        end
      end

      protected

      sig { returns(String) }
      def failure_message
        'Unauthorized'
      end

      sig { abstract.returns(T::Boolean) }
      def authorized?; end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clean-architecture-6.1.0 lib/clean_architecture/checks/authorization.rb
clean-architecture-6.0.0 lib/clean_architecture/checks/authorization.rb