Skip to content

Commit

Permalink
Improve interceptor/Email.block docs
Browse files Browse the repository at this point in the history
What changed?
============

We improve the interceptor and Email.block docs.

In particular, we update the module doc in the Interceptor behaviour to
use the `Email.block` function rather than `Email.intercept` (which was
the function name in a previous iteration).

We also add docs to the `def block` function in `Bamboo.Email` so that
it has its own documentation.
  • Loading branch information
germsvel committed Apr 9, 2021
1 parent fbf148a commit 3c658a7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ examples.

## Interceptors

It's possible to configure per Mailer interceptors. Interceptors allow
to modify / intercept (block) email on the fly.
It's possible to configure per Mailer interceptors. Interceptors allow you to
modify or block emails on the fly.

```elixir
# config/config.exs
Expand All @@ -273,7 +273,8 @@ config :my_app, MyApp.Mailer,
end
```

An interceptor must implement the `Bamboo.Interceptor` behaviour. To prevent email being sent, you can block it with `Bamboo.Email.block/1`.
An interceptor must implement the `Bamboo.Interceptor` behaviour. To prevent
email being sent, you can block it with `Bamboo.Email.block/1`.

```elixir
# some/path/within/your/app/deny_list_interceptor.ex
Expand Down
10 changes: 10 additions & 0 deletions lib/bamboo/email.ex
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,16 @@ defmodule Bamboo.Email do
%{email | attachments: [Bamboo.Attachment.new(path, opts) | attachments]}
end

@doc ~S"""
Marks an email as blocked to prevent it from being sent out. This is meant to
be used from an interceptor. To learn more about interceptors, see the
`Bamboo.Interceptor` behaviour.
## Example
iex> Bamboo.Email.block(%Bamboo.Email{blocked: false})
%Bamboo.Email{blocked: true}
"""
def block(email) do
%{email | blocked: true}
end
Expand Down
5 changes: 3 additions & 2 deletions lib/bamboo/interceptor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ defmodule Bamboo.Interceptor do
@moduledoc ~S"""
Behaviour for creating an Interceptor.
An interceptor allow to modify / block an email before it is sent. To block an email, it must be marked as intercepted with `Bamboo.Email.intercept/1`.
An interceptor allows you to modify or block an email before it is sent. To
block an email, it must be marked as blocked with `Bamboo.Email.block/1`.
## Example
Expand All @@ -12,7 +13,7 @@ defmodule Bamboo.Interceptor do
def call(email) do
if email.to in @deny_list do
Bamboo.Email.intercept(email)
Bamboo.Email.block(email)
else
email
end
Expand Down
1 change: 1 addition & 0 deletions test/lib/bamboo/email_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule Bamboo.EmailTest do
use ExUnit.Case
doctest Bamboo.Email

import Bamboo.Email

Expand Down

0 comments on commit 3c658a7

Please sign in to comment.