Skip to content

Commit

Permalink
Fix the problem with 0-arity functions without parens
Browse files Browse the repository at this point in the history
We're now able to intercept these functions as expected.
  • Loading branch information
amalbuquerque committed Nov 2, 2019
1 parent a469379 commit b78a12d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Known issues

* intercepted functions without arguments that don't have `()` isn't working (e.g. `def foo, do: 123`)
- None at this time :)

# Changelog for v0.5.2

Expand Down
5 changes: 5 additions & 0 deletions lib/configuration/configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ defmodule Interceptor.Configuration do
get_interceptor_module_function_for(mfa_to_intercept, interception_type)
end

def get_interceptor_module_function_for({module, function, nil = _arity} = to_intercept, interception_type) do
# functions with arity 0 without parens have their arity as nil
get_interceptor_module_function_for({module, function, 0}, interception_type)
end

def get_interceptor_module_function_for({module, function, _arity} = to_intercept, interception_type) do
interception_configuration = get_configuration(module)
configuration = interception_configuration[to_intercept]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ end
defmodule AnnotatedInterceptedOnBefore4 do
use Interceptor.Annotated

# TODO: Solve known issue 1
@intercept true
def to_intercept(), do: "Hello, even without args"
def to_intercept, do: "Hello, even without args"

@intercept true
def bla, do: 123
Expand Down
3 changes: 1 addition & 2 deletions test/intercepted_modules/do_block/intercepted_on_before.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ defmodule InterceptedOnBefore4 do
require Interceptor, as: I

I.intercept do
# TODO: Solve known issue 1
def to_intercept(), do: "Hello, even without args"
def to_intercept, do: "Hello, even without args"

def bla, do: 123
end
Expand Down

0 comments on commit b78a12d

Please sign in to comment.