2016-09-08 11:34:42 +02:00
|
|
|
defmodule Ejabberd.Config.Validator.Attrs do
|
|
|
|
@moduledoc """
|
|
|
|
Validator module used to validate attributes.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import Ejabberd.Config.ValidatorUtility
|
|
|
|
alias Ejabberd.Config.Attr
|
2024-03-05 13:05:05 +01:00
|
|
|
alias Ejabberd.Config.EjabberdModule
|
|
|
|
|
|
|
|
# TODO: Duplicated from validator.ex !!!
|
|
|
|
@type mod_validation :: {[EjabberdModule.t], EjabberdModule.t, map}
|
2016-09-08 11:34:42 +02:00
|
|
|
|
|
|
|
@doc """
|
|
|
|
Given a module (with the form used for validation)
|
|
|
|
it runs Attr.validate/1 on each attribute and
|
|
|
|
returns the validation tuple with the errors updated, if found.
|
|
|
|
"""
|
|
|
|
@spec validate(mod_validation) :: mod_validation
|
|
|
|
def validate({modules, mod, errors}) do
|
|
|
|
errors = Enum.reduce mod.attrs, errors, fn(attr, err) ->
|
2024-03-05 12:48:26 +01:00
|
|
|
case Attr.validate([attr]) do
|
|
|
|
[{:ok, _attr}] -> err
|
|
|
|
[{:error, attr, cause}] -> put_error(err, :attribute, {attr, cause})
|
2016-09-08 11:34:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
{modules, mod, errors}
|
|
|
|
end
|
|
|
|
end
|