Rexsilient.Options (Rexsilient v1.0.0)

Copy Markdown View Source

Validates the options given to strategies and recover modules.

The built-in modules use it in their init/1, and custom ones can too, so that invalid options fail the same way: with an ArgumentError that Rexsilient raises again with the declaration's name.

@impl true
def init(opts) do
  Rexsilient.Options.validate!(opts, delay: :non_neg_integer, budget: :pos_integer)
end

Summary

Types

The type an option must have

Functions

Validates opts against spec, a keyword list of key: type.

Types

type()

@type type() :: :pos_integer | :non_neg_integer

The type an option must have:

  • :pos_integer - an integer greater than 0.

  • :non_neg_integer - an integer greater than or equal to 0.

Functions

validate!(opts, spec)

@spec validate!(opts :: term(), spec :: [{atom(), type()}]) :: %{
  required(atom()) => term()
}

Validates opts against spec, a keyword list of key: type.

Every key in spec is required, and keys not in spec are rejected. Returns the options as a map. Raises ArgumentError otherwise.

Examples

Rexsilient.Options.validate!([threshold: 5], threshold: :pos_integer)
#=> %{threshold: 5}

Rexsilient.Options.validate!([threshold: 0], threshold: :pos_integer)
** (ArgumentError) threshold must be a positive integer, got: 0