# Active Delivery

> A framework that provides an entry point for all types of Rails notifications.

- URL: https://evilmartians.com/opensource/active-delivery
- GitHub: https://github.com/palkan/active_delivery
- Authors: Vladimir Dementyev

---

Active Delivery is a framework that provides an entry point for all types of Ruby on Rails notifications: mailers, push notifications, etc. It helps rewrite code, making it simpler and makes performing tests more elegant.

*Note*: this Ruby gem could be used without Rails or Active Support.

## The problem

We need a way to handle different notification _channels_ (mail, push) in one place.

From the business-logic point of view, we want to _notify_ a user, hence we need a _separate abstraction layer_ as an entry point to different types of notifications.

## The solution

Here comes _Active Delivery_.

In the simplest case when we have only mailers, Active Delivery is just a wrapper for Mailer with (possibly) some additional logic provided (e.g., preventing emails to unsubscribed users).

## Motivations behind Active Delivery:

- Organize notifications related logic:

```ruby
# Before
def after_some_action
  MyMailer.with(user: user).some_action.deliver_later if user.receive_emails?
  NotifyService.send_notification(user, "action") if whatever_else?
end

# After
def after_some_action
  MyDelivery.with(user: user).notify(:some_action)
end
```

- Better testability.
