-
Notifications
You must be signed in to change notification settings - Fork 0
/
bad_looking_code.ex
38 lines (30 loc) · 975 Bytes
/
bad_looking_code.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
defmodule BadLookingCode do
use GenServer
def handle_call({:event, url, bucket}, _from, state) do
state = if state.current_bucket do
delete_current_bucket(state)
new_bucket = %{prefix: "events", data: []}
%{state | current_bucket: new_bucket}
else
state
end
state = set_new_listeners(state)
if good_url?(state, url) do
hooks = before_hooks(state, url)
good_hooks = hooks
|> Enum.map(&("act_#{&1}"))
|> Enum.filter(&(!Regex.match?(&1, ~r/\d{4}-\d{2}-\d{2}/)))
|> eval_hook(true)
Logger.info("Good before hooks: #{inspect good_hooks}")
hooks = after_hooks(state, url)
good_hooks = hooks
|> Enum.map(&("act_#{&1}_a"))
|> Enum.filter(&(!Regex.match?(&1, ~r/\d{4}-\d{2}-\d{2}/)))
|> eval_hook(true)
Logger.info("Good after hooks: #{inspect good_hooks}")
{:reply, {good_hooks, url}, state}
else
{:reply, bucket, state}
end
end
end