Sha256: 2b947347c43c79f52a7cf3e6ae6624c9da2b8357e42c370d96bee7c9e388b821

Contents?: true

Size: 545 Bytes

Versions: 2

Compression:

Stored size: 545 Bytes

Contents

# frozen_string_literal: true

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

    attr_reader :allowed_types

    def initialize(types)
      @allowed_types = Array(types).map(&:to_sym).to_set.freeze
    end

    def type?(type)
      allowed_types.member?(type)
    end

    def type!(type)
      return type if type?(type)

      raise Error::UnexpectedType.build(type: type, allowed_types: allowed_types)
    end

    def type_and_value!(data)
      type!(data.type)

      nil
    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.rb
bcdd-result-0.5.0 lib/bcdd/result/expectations/contract/for_types.rb