Elex.AshValidation (Elex v0.2.1)
View SourceAsh resource validation for Elex expression strings.
Validates that a string attribute contains a syntactically valid expression that
type-checks against a Elex.Context and returns the expected type.
This module is only compiled when Ash.Resource.Validation is available (the :ash
dependency is optional).
Examples
defmodule MyApp.Resource do
use Ash.Resource
attributes do
attribute :formula, :string do
allow_nil? false
end
end
validations do
validate Elex.AshValidation,
attribute: :formula,
context: Elex.new_context(),
expected_type: :decimal
end
endOptions
:attribute(required) — Atom name of the attribute containing the expression:context(required) — AElex.Contextdefining allowed variables and functions:expected_type(required) — Expected result type (:decimal,:boolean, or:string):add_value_type_from_attribute— When set to an attribute atom, adds a"value"variable to the context with the type from that attribute's current value:description— Optional description shown in validation error messages