View Source Arke.Validator (Arke v1.1.33)

This module provide validation before assign a certain value to an {arke_struct}

Link to this section Summary

Functions

Function to check the given data based on the fields in the reference schema.

Check if the value can be assigned to a given parameter in a specific schema struct.

Link to this section Types

@type func_return() :: {:ok, Arke.Core.Unit.t()} | Arke.Utils.ErrorGenerator.t()

Link to this section Functions

Link to this function

get_default_value(parameter, value)

View Source
Link to this function

validate(unit, persistence_fn, project \\ :arke_system)

View Source
@spec validate(
  unit :: Arke.Core.Unit.t(),
  peristence_fn :: (() -> any()),
  project :: atom()
) ::
  func_return()

Function to check the given data based on the fields in the reference schema.

parameters

Parameters

  • unit => => %Arke.Core.Unit{} => unit to add
  • persistence_fn => fun.() => function containng the action that will be performed on the Repo
  • project => :atom => identify the Arke.Core.Project

example

Example

iex> schema = Arke.Core.Arke.new
...> param = Arke.Core.Parameter.new(%{type: :string,opts: [id: :name]})
...> schema = Arke.Core.Arke.add_parameter(schema, param)
...> Arke.Validator.validate(%{arke: schema, data: %{name: "test"}})

return

Return

%{:ok,_}
%{:error, [message]}
Link to this function

validate_parameter(arke, parameter, value, project \\ :arke_system)

View Source
@spec validate_parameter(
  arke :: Arke.Core.Arke.t(),
  parameter :: Sring.t() | atom() | Arke.Core.Parameter.parameter_struct(),
  value :: String.t() | number() | atom() | boolean() | map() | list(),
  project :: atom()
) :: func_return()

Check if the value can be assigned to a given parameter in a specific schema struct.

parameters

Parameters

  • schema_struct => %{arke_struct} => the element where to find and check the field
  • field => :atom => the id of the paramater
  • value => any => the value we want to assign to the above field
  • project => :atom => identify the Arke.Core.Project

example

Example

  iex> Arke.Boundary.ArkeValidator.validate_field(schema_struct, :field_id, value_to_check)

returns

Returns

{value,[]} if success
{value,["parameter label", message ]} in case of error