Sha256: fa42b097aba150b6077711cd2faf5634cb17f22ab3e315451697844f688465c1

Contents?: true

Size: 977 Bytes

Versions: 12

Compression:

Stored size: 977 Bytes

Contents

# frozen_string_literal: true

class BCDD::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

12 entries across 12 versions & 1 rubygems

Version Path
bcdd-result-1.1.0 lib/bcdd/result/handler/allowed_types.rb
bcdd-result-1.0.0 lib/bcdd/result/handler/allowed_types.rb
bcdd-result-0.13.0 lib/bcdd/result/handler/allowed_types.rb
bcdd-result-0.12.0 lib/bcdd/result/handler/allowed_types.rb
bcdd-result-0.11.0 lib/bcdd/result/handler/allowed_types.rb
bcdd-result-0.10.0 lib/bcdd/result/handler/allowed_types.rb
bcdd-result-0.9.1 lib/bcdd/result/handler/allowed_types.rb
bcdd-result-0.9.0 lib/bcdd/result/handler/allowed_types.rb
bcdd-result-0.8.0 lib/bcdd/result/handler/allowed_types.rb
bcdd-result-0.7.0 lib/bcdd/result/handler/allowed_types.rb
bcdd-result-0.6.0 lib/bcdd/result/handler/allowed_types.rb
bcdd-result-0.5.0 lib/bcdd/result/handler/allowed_types.rb