chrismccord / mailgun

Elixir Mailgun Client
MIT License
194 stars 95 forks source link

fix(Mailgun.Client): prevent __using__ from changing context #15

Closed Gazler closed 9 years ago

Gazler commented 9 years ago

When doing something like:

defmodule MyApp.Mailer do
  defmacro __using__(_opts) do
    quote do
      config = Application.get_env(:my_app, MyApp.Mailer)
      use Mailgun.Client,
        domain: config[:mailgun_domain],
        key: config[:mailgun_key],
        mode: config[:mode],
        test_file_path: config[:test_file_path]

      @from "noreply@myapp.io"
    end
  end
end

An error is raised :

Compilation error on file welcome_mailer.ex == (CompileError) welcome_mailer.ex:2: function config/0 undefined (stdlib) lists.erl:1336: :lists.foreach/2 (stdlib) erl_eval.erl:657: :erl_eval.do_apply/6

The context is now preserved to allow the client to be wrapped.

This closes #14

chrismccord commented 9 years ago

<3 <3 <3