Sha256: c0c5898a6f95c9e5e19326e6a28bd0b7e1e17fed6f2817391e8ccc350d0248f6

Contents?: true

Size: 978 Bytes

Versions: 1

Compression:

Stored size: 978 Bytes

Contents

# frozen_string_literal: true

class Solid::Result
  class Handler
    class AllowedTypes
      attr_reader :unchecked, :type_checker

      def initialize(type_checker)
        @type_checker = type_checker

        @expectations = type_checker.expectations

        @unchecked = @expectations.allowed_types.dup
      end

      def allow?(types)
        check!(types, type_checker.allow?(types))
      end

      def allow_success?(types)
        unchecked.subtract(@expectations.success.allowed_types) if types.empty?

        check!(types, type_checker.allow_success?(types))
      end

      def allow_failure?(types)
        unchecked.subtract(@expectations.failure.allowed_types) if types.empty?

        check!(types, type_checker.allow_failure?(types))
      end

      def all_checked?
        unchecked.empty?
      end

      private

      def check!(types, checked)
        unchecked.subtract(types) unless all_checked?

        checked
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solid-result-2.0.0 lib/solid/result/handler/allowed_types.rb