Permalink
Browse files

Added AssertHash to Resto namespace

  • Loading branch information...
Anders Törnqvist
Anders Törnqvist committed Jun 10, 2011
1 parent b2c5f5f commit d28b2427b186b4dc8646415e6d8e76011c0f615e
Showing with 14 additions and 12 deletions.
  1. +14 −12 lib/resto/extra/assert_hash.rb
@@ -1,20 +1,22 @@
# encoding: utf-8
-class AssertHash
+module Resto
+ class AssertHash
- def self.keys(hash, *valid_keys)
- hash ||= {}
+ def self.keys(hash, *valid_keys)
+ hash ||= {}
- hash.each { |key, value| hash[key.to_sym] = hash.delete(key) }
+ hash.each { |key, value| hash[key.to_sym] = hash.delete(key) }
- known_keys = [valid_keys].flatten
- unknown_keys = hash.keys - known_keys
- unless unknown_keys.empty?
- unknown = "Invalid key(s): #{unknown_keys.join(", ")}"
- known = "Valid key(s): #{known_keys.join(", ")}"
- raise(ArgumentError, "#{unknown} \n #{known}")
- end
+ known_keys = [valid_keys].flatten
+ unknown_keys = hash.keys - known_keys
+ unless unknown_keys.empty?
+ unknown = "Invalid key(s): #{unknown_keys.join(", ")}"
+ known = "Valid key(s): #{known_keys.join(", ")}"
+ raise(ArgumentError, "#{unknown} \n #{known}")
+ end
- hash
+ hash
+ end
end
end

0 comments on commit d28b242

Please sign in to comment.