Zot.Context (zot v0.12.0)

View Source

Context management for parsing / validating values.

Summary

Types

Represents a segment in a path.

t()

Zot's context struct encapsulates all that is needed to parse and validate a value.

Functions

Appends new issues to the context, what causes the context to be marked as invalid.

Increments the context's score by the given amount.

Creates a new context.

Parses the given context.

Puts the given path into the context.

Unwraps the Context into an :ok|:error tuple.

Checks if the context is valid.

Types

segment()

@type segment() :: String.t() | atom() | non_neg_integer()

Represents a segment in a path.

t()

@type t() :: %Zot.Context{
  input: term(),
  issues: [Zot.Issue.t()],
  opts: keyword(),
  output: term(),
  path: [segment()],
  score: integer(),
  type: struct(),
  valid?: boolean()
}

Zot's context struct encapsulates all that is needed to parse and validate a value.

Functions

append_issues(ctx, new_issues)

@spec append_issues(t(), [Zot.Issue.t()]) :: t()

Appends new issues to the context, what causes the context to be marked as invalid.

inc_score(ctx, inc \\ 1)

@spec inc_score(t(), integer()) :: t()

Increments the context's score by the given amount.

new(type, input, opts \\ [])

@spec new(type, input, opts) :: t()
when type: struct(), input: term(), opts: keyword()

Creates a new context.

parse(ctx)

@spec parse(t()) :: t()

Parses the given context.

put_path(ctx, path)

@spec put_path(t(), [segment()]) :: t()

Puts the given path into the context.

unwrap(ctx)

@spec unwrap(t()) :: {:ok, term()} | {:error, [Zot.Issue.t(), ...]}

Unwraps the Context into an :ok|:error tuple.

valid?(ctx)

@spec valid?(t()) :: boolean()

Checks if the context is valid.