Class: WebMock::HashValidator
- Inherits:
-
Object
- Object
- WebMock::HashValidator
- Defined in:
- lib/webmock/util/hash_validator.rb
Instance Method Summary collapse
-
#initialize(hash) ⇒ HashValidator
constructor
A new instance of HashValidator.
-
#validate_keys(*valid_keys) ⇒ Object
This code is based on github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/keys.rb.
Constructor Details
#initialize(hash) ⇒ HashValidator
Returns a new instance of HashValidator.
3 4 5 |
# File 'lib/webmock/util/hash_validator.rb', line 3 def initialize(hash) @hash = hash end |
Instance Method Details
#validate_keys(*valid_keys) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/webmock/util/hash_validator.rb', line 8 def validate_keys(*valid_keys) valid_keys.flatten! @hash.each_key do |k| unless valid_keys.include?(k) raise ArgumentError.new("Unknown key: #{k.inspect}. Valid keys are: #{valid_keys.map(&:inspect).join(', ')}") end end end |