defmodule PotionIngredients.Utils.Messages do defmacro __using__(opts) do [messages: messages] = opts import PotionIngredients.Utils quote do def get_message(message) do paths = String.split(message, ".") |> Enum.map(fn path -> try do String.to_existing_atom(path) rescue _e -> nil end end) filtered = Enum.filter(paths, fn path -> !is_nil(path) end) same_length = length(filtered) == length(paths) iif(same_length == true, get_in(unquote(messages), filtered), nil) end end end end