Sha256: 6ea58fdb18c650a02c6616078018ed795bbf9621a0b259490974edf10f85dc6e

Contents?: true

Size: 984 Bytes

Versions: 2

Compression:

Stored size: 984 Bytes

Contents

# typed: strict
# frozen_string_literal: true

module CleanArchitecture
  module Entities
    class FailureType < T::Enum
      enums do
        Error = new('internal_server_error')
        ExpectationFailed = new('expectation_failed')
        NotFound = new('not_found')
        Unauthorized = new('unauthorized')
        UnprocessableEntity = new('unprocessable_entity')
      end
    end

    class FailureDetails < T::Struct
      extend T::Sig

      include T::Struct::ActsAsComparable

      const :type, FailureType
      const :message, String

      sig { params(array: T::Array[Object]).returns(FailureDetails) }
      def self.from_array(array)
        new(
          message: array.map(&:to_s).join(', '),
          type: FailureType::Error
        )
      end

      sig { params(string: String).returns(FailureDetails) }
      def self.from_string(string)
        new(
          message: string,
          type: FailureType::Error
        )
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clean-architecture-6.1.0 lib/clean_architecture/entities/failure_details.rb
clean-architecture-6.0.0 lib/clean_architecture/entities/failure_details.rb