defmodule Mahaul do @external_resource "README.md" @moduledoc File.read!("README.md") |> String.replace("# Mahaul\n\n", "", global: false) @version "0.2.0" @doc false def version, do: @version @doc false defmacro __using__(opts) do quote location: :keep, bind_quoted: [opts: opts] do require Logger alias Mahaul.Helpers Enum.each(opts, fn {key, val} -> str_key = Atom.to_string(key) fn_name = str_key |> String.downcase() |> String.to_atom() def unquote(fn_name)() do elem(Helpers.get_env(unquote(key), unquote(val)), 1) end end) @doc ~s""" Same as `validate/0` except that it raises exception if the required environment variables are not set or are invalid. """ def validate! do Logger.info("#{__MODULE__}: validating environment variables...") Helpers.validate!(Helpers.parse_all(unquote(opts))) Logger.info("#{__MODULE__}: environment variables ok") end @doc ~s""" Validates all currently set environment variables against the app required environment variables. Return {:ok} if all required environment variables are present and can be parsed as per the given configurations. It otherwise return {:error, error_string} with the list of errors. """ def validate do Helpers.validate(Helpers.parse_all(unquote(opts))) end end end end