keyvalidatable
Description
Validate shortage/excess keys in pairs.
Usage
Validate option parameters(hash-argument)
require 'keyvalidatable'
class Foo
def func()
KeyValidatable.validate_keys , must: [:a, :b], let: [:c]
p "#{} is valid"
rescue
p $!
end
end
foo = Foo.new
foo.func(a: 1, b: 2, c: 3) #=> "{:a=>1, :b=>2, :c=>3} is valid"
foo.func(a: 1, c: 3) #=> InvalidKeysError: Shortage: [:b] / Excess: []
foo.func(a: 1, b: 2) #=> "{:a=>1, :b=>2} is valid"
foo.func(a: 1, b: 2, c: 3, d: 4) #=> InvalidKeysError: Shortage: [] / Excess: [:d]
Requirements
- Ruby - 1.9.3 or later
Install
$ gem install keyvalidatable
Link
License
The MIT X11 License
Copyright (c) 2012 Kenichi Kamiya
See MIT-LICENSE for further details.