Sha256: 1754de2bfce0492e708d87f549d980b719a012c9a75b4c64646420a3b88a9072

Contents?: true

Size: 503 Bytes

Versions: 8

Compression:

Stored size: 503 Bytes

Contents

# frozen_string_literal: true

# Used to validate incoming parameter hash.
class VerifyKeyInHash
  def self.call(hash, key)
    VerifyKeyInHash.new(hash, key).call
  end

  def call
    raise KeyError, no_key_message unless key_in_hash?
  end

  protected

  def initialize(hash, key)
    @hash = hash
    @key = key
    self
  end

  private

  attr_reader :hash, :key

  def key_in_hash?
    hash.key? key
  end

  def no_key_message
    "No key :#{key} in #{hash}!"
  end
end # class VerifyKeyInHash

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
prolog_minitest_matchers-0.5.4 lib/prolog_minitest_matchers/matchers/asserters/verify_key_in_hash.rb
prolog_minitest_matchers-0.5.3 lib/prolog_minitest_matchers/matchers/asserters/verify_key_in_hash.rb
prolog_minitest_matchers-0.5.2 lib/prolog_minitest_matchers/matchers/asserters/verify_key_in_hash.rb
prolog_minitest_matchers-0.5.1 lib/prolog_minitest_matchers/matchers/asserters/verify_key_in_hash.rb
prolog_minitest_matchers-0.5.0 lib/prolog_minitest_matchers/matchers/asserters/verify_key_in_hash.rb
prolog_minitest_matchers-0.4.0 lib/prolog_minitest_matchers/matchers/asserters/verify_key_in_hash.rb
prolog_minitest_matchers-0.3.1 lib/prolog_minitest_matchers/matchers/asserters/verify_key_in_hash.rb
prolog_minitest_matchers-0.3.0 lib/prolog_minitest_matchers/matchers/asserters/verify_key_in_hash.rb