Skip to content

Decorator used with Ecto #29

@ludwikbukowski

Description

@ludwikbukowski

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions