Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decorator used with Ecto #29

Open
ludwikbukowski opened this issue Oct 2, 2018 · 3 comments
Open

Decorator used with Ecto #29

ludwikbukowski opened this issue Oct 2, 2018 · 3 comments

Comments

@ludwikbukowski
Copy link
Contributor

ludwikbukowski commented Oct 2, 2018

Let's say I'd like to decorate_all functions that are injected by Ecto.Repo. I am struggling with this:

defmodule App.Repo do
  use Ecto.Repo, otp_app: :app
  use Decorator.Define
  @decorate_all function_result(:test)

  def function_result(add, body, _context) do
    quote do
      {unquote(add), unquote(body)}
    end
  end

(...)

Firstly, it seems not to work due to warning:

== Compilation error in file lib/app/repo.ex ==
** (ArgumentError) cannot make function __pool__/0 overridable because it was not defined
    (elixir) lib/module.ex:913: anonymous fn/2 in Module.make_overridable/2
    (stdlib) lists.erl:1338: :lists.foreach/2
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (stdlib) erl_eval.erl:228: :erl_eval.expr/5
    (stdlib) erl_eval.erl:229: :erl_eval.expr/5
    /lib/app/repo.ex:1: Decorator.Decorate.before_compile/1

Once I force filter out __pool__ function from decoration, it compiles but only few functions are decorated. Most of them are not

@ludwikbukowski
Copy link
Contributor Author

Most likely thats because Ecto defines his own before_compile macro and does a lot of magic generally

@arjan
Copy link
Owner

arjan commented Oct 3, 2018

Hmmm 2 incompatible forms of magic within one module, interesting...

@aspett
Copy link

aspett commented Oct 9, 2018

Also appears to not work with Phoenix.View.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants