View Source Sonyflakex.Config (Sonyflakex v0.3.0)

Configuration validation helpers

Summary

Functions

Sets default value for an option if option is not set in option list. Default value is set from a callback.

Validates option value integer can be set as a binary in a field with a limited number of bits.

Validates option value is a function reference with input arity. This is checked only if value is set.

Validates option value is an integer. This is checked only if value is set.

Validates machine ID value using check_machine_id function if option is set. Returns validation error if check_machine_id returns false.

Checks if integer value binary representatino would fit in a number of bits.

Functions

Link to this function

set_default(opts, option_name, default_callback)

View Source
@spec set_default(keyword(), atom(), (-> any())) :: {:ok, keyword()}

Sets default value for an option if option is not set in option list. Default value is set from a callback.

Args:

  • opts: Configuration options.
  • option_name: Key for configuration option being validated.
  • default_callback: Function that returns a default value.
Link to this function

validate_bit_option_length(opts, option_name, max_bits)

View Source
@spec validate_bit_option_length(keyword(), atom(), non_neg_integer()) ::
  {:error, {:value_too_big, atom(), integer()}} | {:ok, keyword()}

Validates option value integer can be set as a binary in a field with a limited number of bits.

Args:

  • opts: Configuration options
  • option_name: Key for configuration option being validated.
  • max_bits: Maximum number of bits that would fit the option value.
Link to this function

validate_is_function(opts, option_name, arity)

View Source
@spec validate_is_function(keyword(), atom(), non_neg_integer()) ::
  {:error, {:non_function, atom(), any()}}
  | {:error, {:wrong_function_arity, atom(), any()}}
  | {:ok, keyword()}

Validates option value is a function reference with input arity. This is checked only if value is set.

Link to this function

validate_is_integer(opts, option_name)

View Source
@spec validate_is_integer(
  keyword(),
  atom()
) :: {:error, {:non_integer, atom(), any()}} | {:ok, keyword()}

Validates option value is an integer. This is checked only if value is set.

Link to this function

validate_machine_id(opts, check_machine_id_option, machine_id_option)

View Source
@spec validate_machine_id(keyword(), atom(), atom()) ::
  {:error, {:machine_id_not_unique, integer()}} | {:ok, keyword()}

Validates machine ID value using check_machine_id function if option is set. Returns validation error if check_machine_id returns false.

Link to this function

value_fits_in_bits(value, length_bits)

View Source
@spec value_fits_in_bits(integer(), non_neg_integer()) :: boolean()

Checks if integer value binary representatino would fit in a number of bits.

Examples

iex> Sonyflakex.Config.value_fits_in_bits(255, 8)
true