Sha256: d78810d5e5ecde45bde48691f8e1c9f3013d7554355e6afe4a1575051decc4e6

Contents?: true

Size: 887 Bytes

Versions: 2

Compression:

Stored size: 887 Bytes

Contents

# frozen_string_literal: true

class BCDD::Result::Expectations
  class Contract::ForTypesAndValues
    include Contract::Interface

    def initialize(types_and_values)
      @types_and_values = types_and_values.transform_keys(&:to_sym)

      @types_contract = Contract::ForTypes.new(@types_and_values.keys)
    end

    def allowed_types
      @types_contract.allowed_types
    end

    def type?(type)
      @types_contract.type?(type)
    end

    def type!(type)
      @types_contract.type!(type)
    end

    def type_and_value!(data)
      type = data.type
      value = data.value
      allowed_value = @types_and_values[type!(type)]

      return value if allowed_value === value

      raise Error::UnexpectedValue.build(type: type, value: value)
    rescue NoMatchingPatternError
      raise Error::UnexpectedValue.build(type: data.type, value: data.value)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bcdd-result-0.6.0 lib/bcdd/result/expectations/contract/for_types_and_values.rb
bcdd-result-0.5.0 lib/bcdd/result/expectations/contract/for_types_and_values.rb