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
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.
@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.
@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.
@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.
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.
@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