aboutsummaryrefslogtreecommitdiff
path: root/lib/ejabberd/config/validator/validator_dependencies.ex
blob: d44c8a136f0f99cbaea4ee96c5c2fd5b98239528 (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
29
30
defmodule Ejabberd.Config.Validator.Dependencies do
  @moduledoc """
  Validator module used to validate dependencies specified
  with the @dependency annotation.
  """

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

  @doc """
  Given a module (with the form used for validation)
  it checks if the @dependency annotation is respected and
  returns the validation tuple with the errors updated, if found.
  """
  @spec validate(mod_validation) :: mod_validation
  def validate({modules, mod, errors}) do
    module_names = extract_module_names(modules)
    dependencies = mod.attrs[:dependency]

    errors = Enum.reduce dependencies, errors, fn(req_module, err) ->
      case req_module in module_names do
        true -> err
        false -> put_error(err, :dependency, {req_module, :not_found})
      end
    end

    {modules, mod, errors}
  end
end