Sha256: 552ebdbeaeb30738e75d1dc0daaf0bedaf0ca77374622d7541e4c927f7ddecd6
Contents?: true
Size: 843 Bytes
Versions: 2
Compression:
Stored size: 843 Bytes
Contents
# frozen_string_literal: true module BCDD::Result::Contract class TypeChecker attr_reader :result_type, :expectations def initialize(result_type, expectations:) @result_type = result_type @expectations = expectations end def allow!(type) expectations.type!(type) end def allow?(types) validate(types, expected: expectations, allow_empty: false) end def allow_success?(types) validate(types, expected: expectations.success, allow_empty: true) end def allow_failure?(types) validate(types, expected: expectations.failure, allow_empty: true) end private def validate(types, expected:, allow_empty:) (allow_empty && types.empty?) || types.any? { |type| expected.type!(type) == result_type } end end private_constant :TypeChecker end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
bcdd-result-1.1.0 | lib/bcdd/result/contract/type_checker.rb |
bcdd-result-1.0.0 | lib/bcdd/result/contract/type_checker.rb |