aboutsummaryrefslogtreecommitdiff
path: root/lib/ejabberd/config/validator/validator_attrs.ex
blob: 6a85c068dedcfc2b71aa7bb6588069b47e8008ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
defmodule Ejabberd.Config.Validator.Attrs do
  @moduledoc """
  Validator module used to validate attributes.
  """

  # TODO: Duplicated from validator.ex !!!
  @type mod_validation :: {[EjabberdModule.t], EjabberdModule.t, map}

  import Ejabberd.Config.ValidatorUtility
  alias Ejabberd.Config.Attr

  @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) ->
      case Attr.validate(attr) do
        {:ok, _attr} -> err
        {:error, attr, cause} -> put_error(err, :attribute, {attr, cause})
      end
    end

    {modules, mod, errors}
  end
end