-
Notifications
You must be signed in to change notification settings - Fork 23
/
helpers.ex
45 lines (38 loc) · 1.26 KB
/
helpers.ex
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
defmodule Cipher.Helpers do
@moduledoc """
require Cipher.Helpers, as: H # the cool way
"""
@doc """
Convenience to get environment bits. Avoid all that repetitive
`Application.get_env( :myapp, :blah, :blah)` noise.
"""
def env(key, default \\ nil), do: env(:cipher, key, default)
def env(app, key, default), do: Application.get_env(app, key, default)
@doc """
Spit to output any passed variable, with location information.
"""
defmacro spit(obj \\ "", inspect_opts \\ []) do
quote do
%{file: file, line: line} = __ENV__
name = Process.info(self)[:registered_name]
chain = [ :bright, :red, "\n\n#{file}:#{line}",
:normal, "\n #{inspect self}", :green," #{name}"]
msg = inspect(unquote(obj),unquote(inspect_opts))
if String.length(msg) > 2, do: chain = chain ++ [:red, "\n\n#{msg}"]
(chain ++ ["\n\n", :reset]) |> IO.ANSI.format(true) |> IO.puts
unquote(obj)
end
end
@doc """
Print to stdout a _TODO_ message, with location information.
"""
defmacro todo(msg \\ "") do
quote do
%{file: file, line: line} = __ENV__
[ :yellow, "\nTODO: #{file}:#{line} #{unquote(msg)}\n", :reset]
|> IO.ANSI.format(true)
|> IO.puts
:todo
end
end
end