View Source Peri.Parser (peri v0.2.11)
The Peri.Parser
module is responsible for managing the state during schema validation.
It centralizes functions to handle updating data, adding errors, and managing the path within
the data structure being validated.
Struct
The Peri.Parser
struct has the following fields:
:data
- The current state of the data being validated.:errors
- A list of errors encountered during validation.:path
- The current path within the data structure being validated.
Summary
Functions
Adds an error to the parser state's list of errors.
Initializes a new Peri.Parser
struct with the given data.
Updates the data in the parser state at the given key with the specified value.
Functions
Adds an error to the parser state's list of errors.
Parameters
state
- The currentPeri.Parser
state.err
- The%Peri.Error{}
struct representing the error to add.
Examples
iex> state = Peri.Parser.new(%{name: "Alice"})
iex> error = %Peri.Error{path: [:name], message: "is required", content: []}
iex> Peri.Parser.add_error(state, error)
%Peri.Parser{data: %{name: "Alice"}, errors: [%Peri.Error{path: [:name], message: "is required", content: []}], path: []}
Initializes a new Peri.Parser
struct with the given data.
Parameters
data
- The initial data to be validated.
Examples
iex> Peri.Parser.new(%{name: "Alice"})
%Peri.Parser{data: %{name: "Alice"}, errors: [], path: []}
Updates the data in the parser state at the given key with the specified value.
Parameters
state
- The currentPeri.Parser
state.key
- The key to update in the data.val
- The value to set at the specified key.
Examples
iex> state = Peri.Parser.new(%{name: "Alice"})
iex> Peri.Parser.update_data(state, :age, 30)
%Peri.Parser{data: %{name: "Alice", age: 30}, errors: [], path: []}