View Source Envio.Utils (envio v1.0.0)
Multipurpose utils, required for the Envío proper functioning, like:
fq_name
to construct fully-qualified names for channels to prevent clashes
Summary
Functions
Returns the anonymous function that either loads the system environment variable or simply returns the value statically loaded from config file.
Produces a fully-qualified name out of namespace in a form of a module name atom and a method name (atom or binary.)
Fetches the value from the map by given key and returns both the value and the map without this key.
Safely converts any term to binary.
Functions
Returns the anonymous function that either loads the system environment variable or simply returns the value statically loaded from config file.
Examples
iex> # config :envio, :binary_value, "FOO"
iex> Envio.Utils.config_value(Application.get_env(:envio, :binary_value)).()
"FOO"
iex> # config :envio, :env_value, {:system, "FOO"}
iex> System.put_env("FOO", "42")
iex> Envio.Utils.config_value(Application.get_env(:envio, :env_value)).()
"42"
@spec fq_name( binary() | atom() | {atom(), atom() | binary()}, nil | atom() | binary() ) :: binary()
Produces a fully-qualified name out of namespace in a form of a module name atom and a method name (atom or binary.)
Examples
iex> Envio.Utils.fq_name("foo")
"foo"
iex> Envio.Utils.fq_name({Foo.Bar, "baz"})
"foo/bar.baz"
iex> Envio.Utils.fq_name(Foo.Bar, "baz")
"foo/bar.baz"
iex> Envio.Utils.fq_name(Foo.Bar, :baz)
"foo/bar.baz"
iex> Envio.Utils.fq_name("Foo.Bar", "baz")
"Foo.Bar.baz"
Fetches the value from the map by given key and returns both the value and the map without this key.
Examples
iex> Envio.Utils.get_delete(%{foo: :bar, baz: 42}, :foo)
{:bar, %{baz: 42}}
iex> Envio.Utils.get_delete(%{baz: 42}, :foo)
{nil, %{baz: 42}}
iex> Envio.Utils.get_delete(%{baz: 42}, :foo, :bar)
{:bar, %{baz: 42}}
Safely converts any term to binary.
Examples
iex> Envio.Utils.smart_to_binary("foo")
"foo"
iex> Envio.Utils.smart_to_binary(42)
"42"
iex> Envio.Utils.smart_to_binary(%{foo: :bar, baz: 42})
"%{foo: :bar, baz: 42}"
iex> Envio.Utils.smart_to_binary([foo: :bar, baz: 42])
"[foo: :bar, baz: 42]"