View Source Sonyflakex.Config (Sonyflakex v0.2.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 an integer. This is checked only if value is set.

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_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

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