Filtrex v0.1.0 Filtrex.Condition behaviour

Filtrex.Condition is an abstract module for parsing conditions.

Summary

Functions

Parses a condition by dynamically delegating to modules

Generates an error description for a generic parse error

Generates an error description for a parse error resulting from an invalid value type

Helper method to validate whether a value is in a list

Helper method to validate whether a value is a binary

Functions

parse(config, map)

Parses a condition by dynamically delegating to modules

It delegates based on the type field of the options map (e.g. Filtrex.Condition.Text for the type "text"). Example Input: config:

Filtrex.Condition.parse(%{
  text: %{keys: ~w(title comments)}  # passed to the specific condition
}, %{
  type: string,                      # converted to Filtrex.Condition."__" dynamically
  column: string,
  comparator: string,
  value: string,
  inverse: boolean                   # inverts the comparator logic
})
parse_error(value, type, filter_type)

Specs

parse_error(any, Atom.t, Atom.t) :: String.t

Generates an error description for a generic parse error

parse_value_type_error(column, filter_type)

Specs

parse_value_type_error(any, Atom.t) :: String.t

Generates an error description for a parse error resulting from an invalid value type

validate_in(value, list)

Specs

validate_in(any, List.t) :: nil | any

Helper method to validate whether a value is in a list

validate_is_binary(value)

Specs

validate_is_binary(any) :: nil | String.t

Helper method to validate whether a value is a binary

Macros

encoder(type, comparator, reverse_comparator, expression, values_function \\ {:&, [], [[{:&, [], [1]}]]})

Callbacks

parse(arg0, %{})

Specs

parse(Map.t, %{inverse: boolean, column: String.t, value: any, comparator: String.t}) ::
  {:ok, any} |
  {:error, any}