Packages
guardian
1.0.0-beta.0
2.4.0
2.3.2
2.3.1
2.3.0
2.2.4
2.2.3
2.2.2
2.2.1
2.2.0
2.1.2
2.1.1
2.0.0
1.2.1
1.2.0
retired
1.1.1
1.1.0
1.0.1
1.0.0
1.0.0-beta.1
1.0.0-beta.0
0.14.6
0.14.5
0.14.4
0.14.3
retired
0.14.2
0.14.1
0.14.0
0.13.0
0.12.0
0.11.1
0.10.1
0.10.0
0.9.1
0.9.0
0.8.1
0.8.0
0.7.4
0.7.2
0.7.1
0.7.0
0.6.3
0.6.2
0.6.1
0.6.0
0.5.2
0.5.0
0.4.1
0.4.0
0.3.1
0.3.0
0.2.0
0.1.1
0.1.0
Elixir Authentication framework
Current section
Files
Jump to
Current section
Files
lib/guardian/config.ex
defmodule Guardian.Config do
@moduledoc """
Working with configuration for guardian.
"""
@typedoc """
Configuration values can be given using the following types:
* `{:system, "FOO"}` - Read from the system environment
* `{MyModule, :function_name}` - To call a function and use the result
* `{MyModule, :func, [:some, :args]}` Calls the function on the module with args
* `fn -> :some_value end` - an anonymous function whose result will be used
* any other value
"""
@type config_value :: {:system, String.t} |
{module, atom} |
{module, atom, list(any)} |
fun |
any
@doc """
Resolves possible values from a configuration.
* `{:system, "FOO"}` - reads "FOO" from the environment
* `{m, f}` - Calls function `f` on module `m` and returns the result
* `{m, f, a}` - Calls function `f` on module `m` with arguments `a` and returns the result
* `f` - Calls the function `f` and returns the result
* value - Returns other values as is
"""
@spec resolve_value(value :: config_value) :: any
def resolve_value({:system, name}), do: System.get_env(name)
def resolve_value({m, f}) when is_atom(m) and is_atom(f), do: apply(m, f, [])
def resolve_value({m, f, a}) when is_atom(m) and is_atom(f), do: apply(m, f, a)
def resolve_value(f) when is_function(f, 0), do: apply(f, [])
def resolve_value(v), do: v
end