FeaturevisorSchemas.Refinement (featurevisor_schemas v2.1.0)

Copy Markdown View Source

A check in code that rules cannot express, such as whether a username is taken. check gets the value at path and a FeaturevisorSchemas.CheckInfo, and returns true when the value passes, false when it does not, or {:error, reason} when it cannot tell. It runs after the rules, and only where they found no issue at or inside its path, nor in a field it reads. A check that errors, raises or exits reports refineError.

%FeaturevisorSchemas.Refinement{
  key: "passwordsMatch",
  path: "confirm",
  reads: ["password"],
  message: "Passwords must match",
  check: fn value, info -> value == FeaturevisorSchemas.CheckInfo.read(info, "password") end
}

Summary

Types

t()

@type t() :: %FeaturevisorSchemas.Refinement{
  check: (term(), FeaturevisorSchemas.CheckInfo.t() ->
            boolean() | {:error, term()}),
  key: String.t(),
  message: String.t() | nil,
  path: String.t(),
  reads: [String.t()]
}