module Kind::ASSERT_HASH_KEYS

Public Class Methods

require_all(keys, hash) click to toggle source
# File lib/kind/__lib__/assert_hash_schema.rb, line 5
def self.require_all(keys, hash)
  expected_keys = keys - hash.keys

  unless expected_keys.empty?
    raise KeyError.new("#{hash.inspect} expected to have these keys: #{expected_keys}")
  end

  unexpected_keys = hash.keys - keys

  unless unexpected_keys.empty?
    raise KeyError.new("#{hash.inspect} expected to NOT have these keys: #{unexpected_keys}")
  end

  hash
end