Skip to content
This repository has been archived by the owner on May 20, 2022. It is now read-only.

kachick/keyvalidatable

Repository files navigation

keyvalidatable

  • This repository is archived
  • No longer maintained
  • All versions have been yanked from https://rubygems.org for releasing valuable namespace for others

Build Status

Validate shortage/excess keys in pairs.

Usage

Overview

require 'keyvalidatable'

class Foo
  def func(options)
    KeyValidatable.validate_keys options, must: [:a, :b], let: [:c]

    p "#{options} is valid"
  rescue => err
    p err
  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]

Links

About

Validate shortage/excess keys in pairs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published