Crutches.Keyword

Summary

all_keys_valid?(options, whitelist)

Checks a keyword list for unexpected keys, by using a default list of keys. When a bad key is detected it returns false, else it returns true

validate_keys!(options, whitelist)

Throwing version of Keyword.validate_keys

validate_keys(options, whitelist)

Checks a keyword list for unexpected keys, by using a default list of keys. Returns {:ok, []} if all options are kosher, otherwise {:error, list}, where list is a list of all invalid keys

Functions

all_keys_valid?(options, whitelist)

Checks a keyword list for unexpected keys, by using a default list of keys. When a bad key is detected it returns false, else it returns true.

Examples

iex> Keyword.all_keys_valid?([good: "", good_opt: ".", bad: "!"], [:good, :good_opt])
false

iex> Keyword.all_keys_valid?([good: "", good_opt: "."], [:good, :good_opt])
true
validate_keys(options, whitelist)

Checks a keyword list for unexpected keys, by using a default list of keys. Returns {:ok, []} if all options are kosher, otherwise {:error, list}, where list is a list of all invalid keys.

Examples

iex> Keyword.validate_keys([good: "", good_opt: ""], [:good, :good_opt])
{:ok, []}

iex> Keyword.validate_keys([good: "", bad: ""], [:good])
{:error, [:bad]}
validate_keys!(options, whitelist)

Throwing version of Keyword.validate_keys

Examples

iex> Keyword.validate_keys!([good: "", bad: ""], [:good])
** (ArgumentError) invalid key bad

iex> Keyword.validate_keys!([good: "", bad: "", worse: ""], [:good])
** (ArgumentError) invalid key bad, worse

iex> Keyword.validate_keys!([good: ""], [:good])
true