Skip to content

Commit

Permalink
fix: Dialyzer useless control flow (#73)
Browse files Browse the repository at this point in the history
* fix: Dialyzer useless control flow

* fix: credo
  • Loading branch information
filipeherculano committed Jun 11, 2020
1 parent aa25135 commit 8c16848
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions lib/nebulex/caching/decorators.ex
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,15 @@ defmodule Nebulex.Caching.Decorators do
defp caching_action(action, attrs, block, context) do
cache = attrs[:cache] || raise ArgumentError, "expected cache: to be given as argument"

key_var = Keyword.get(attrs, :key)
key_var =
Keyword.get(
attrs,
:key,
quote(do: :erlang.phash2({unquote(context.module), unquote(context.name)}))
)

keys_var = Keyword.get(attrs, :keys, [])
match_var = Keyword.get(attrs, :match)
match_var = Keyword.get(attrs, :match, quote(do: fn _ -> true end))

opts_var =
attrs
Expand All @@ -241,10 +247,10 @@ defmodule Nebulex.Caching.Decorators do

quote do
cache = unquote(cache)
key = unquote(key_var) || :erlang.phash2({unquote(context.module), unquote(context.name)})
key = unquote(key_var)
keys = unquote(keys_var)
opts = unquote(opts_var)
match = unquote(match_var) || fn _ -> true end
match = unquote(match_var)

unquote(action_logic)
end
Expand All @@ -257,10 +263,11 @@ defmodule Nebulex.Caching.Decorators do
else
value = unquote(block)

if apply(match, [value]) do
cache.set(key, value, opts)
else
with true <- apply(match, [value]),
value <- cache.set(key, value, opts) do
value
else
false -> value
end
end
end
Expand All @@ -287,10 +294,11 @@ defmodule Nebulex.Caching.Decorators do
quote do
value = unquote(block)

if apply(match, [value]) do
cache.set(key, value, opts)
else
with true <- apply(match, [value]),
value <- cache.set(key, value, opts) do
value
else
false -> value
end
end
end
Expand Down

0 comments on commit 8c16848

Please sign in to comment.