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

Build mailer config during runtime #170

Merged

Conversation

smdern
Copy link
Contributor

@smdern smdern commented May 28, 2016

Fixes - #166

@@ -64,17 +64,14 @@ defmodule Bamboo.Mailer do
quote bind_quoted: [opts: opts] do
config = Bamboo.Mailer.parse_opts(__MODULE__, opts)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line still needed? Should it always use the function instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. good catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse_opts was doing a Keyword.fetch!(opts, :otp_app) to enforce that it wasn't omitted. Going to include that in the macro so that can get caught during compile time.

@smdern smdern force-pushed the mailer-config-during-runtime branch from b7fdcac to fbcf969 Compare May 28, 2016 01:10
@spec deliver_now(Bamboo.Email.t) :: Bamboo.Email.t
def deliver_now(email) do
Bamboo.Mailer.deliver_now(@adapter, email, @config)
Bamboo.Mailer.deliver_now(adapter, email, config)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random thoughts: This parses the config 2x per delivery, once to get the config, but again to get adapter which just calls config.adapter. Maybe something like:

conf = config
Bamboo.Mailer.deliver_now(conf.adapter, email, conf)

Premature optimization. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Appreciate the feedback.

@smdern smdern force-pushed the mailer-config-during-runtime branch from fbcf969 to b5deca7 Compare May 28, 2016 01:18
@@ -184,8 +184,7 @@ defmodule Bamboo.Mailer do
end

@doc false
def parse_opts(mailer, opts) do
otp_app = Keyword.fetch!(opts, :otp_app)
def parse_opts(mailer, otp_app) do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ This makes it so that the omitting :otp_app in a Mailer is caught during compile time, but it changes a public method signature. Can add an additional clause def parse_opts(mailer, opts, otp_app) if concerned

Copy link
Contributor

@paulcsmith paulcsmith May 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok because it's not documented and probably shouldn't be used by other devs anyway :)

Good question though!

@geofflane
Copy link

👍

@@ -184,8 +184,7 @@ defmodule Bamboo.Mailer do
end

@doc false
def parse_opts(mailer, opts) do
otp_app = Keyword.fetch!(opts, :otp_app)
def parse_opts(mailer, otp_app) do
config = Application.fetch_env!(otp_app, mailer) |> Enum.into(%{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're working on the config, could you change Enum.into(%{}) into Map.new? That is faster and I think a bit more clear.

@paulcsmith
Copy link
Contributor

Left a few small comments. Overall this looks great though :) Can you ping me when you've had a chance to implement those suggestions? Then I'll merge this in. Thanks!

@smdern smdern force-pushed the mailer-config-during-runtime branch from b5deca7 to 2bae9af Compare May 31, 2016 14:59
@smdern
Copy link
Contributor Author

smdern commented May 31, 2016

Left a few small comments. Overall this looks great though :) Can you ping me when you've had a chance to implement those suggestions? Then I'll merge this in. Thanks!

@paulcsmith feedback addressed.

end

otp_app = Keyword.fetch!(opts, :otp_app)

defp get_config, do: Bamboo.Mailer.parse_opts(__MODULE__, unquote(otp_app))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking this should be called build_config so it implies that there is some sort of work that has to be done whenever it's called

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I like that!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually how do you feel about Bamboo.Mailer.build_config(mailer, otp_app) and then we can just inline it in the functions as config = Bamboo.Mailer.build_config(mailer, unquote(otp_app) ? Seems like build_config would be a better public function than parse_opts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd have to see it first, but it sounds pretty good. Definitely worth a try

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smdern smdern force-pushed the mailer-config-during-runtime branch from d226f86 to da038f5 Compare May 31, 2016 18:13
@smdern smdern force-pushed the mailer-config-during-runtime branch from da038f5 to 174f1b1 Compare May 31, 2016 18:14
@smdern
Copy link
Contributor Author

smdern commented May 31, 2016

@paulcsmith Made the changes.

@paulcsmith paulcsmith merged commit 584ec63 into beam-community:master Jun 13, 2016
@paulcsmith
Copy link
Contributor

Thank you @smdern!

@smdern smdern deleted the mailer-config-during-runtime branch July 22, 2016 22:32
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

Successfully merging this pull request may close these issues.

3 participants