README.md in active_delivery-0.4.2 vs README.md in active_delivery-0.4.3

- old
+ new

@@ -1,7 +1,8 @@ [![Gem Version](https://badge.fury.io/rb/active_delivery.svg)](https://badge.fury.io/rb/active_delivery) -[![Build Status](https://travis-ci.org/palkan/active_delivery.svg?branch=master)](https://travis-ci.org/palkan/active_delivery) +![Build](https://github.com/palkan/active_delivery/workflows/Build/badge.svg) +![JRuby Build](https://github.com/palkan/active_delivery/workflows/JRuby%20Build/badge.svg) # Active Delivery Framework providing an entry point (single _interface_) for all types of notifications: mailers, push notifications, whatever you want. @@ -9,12 +10,13 @@ <a href="https://evilmartians.com/?utm_source=action_policy"> <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a> Requirements: -- Ruby ~> 2.4 +- Ruby ~> 2.5 + **NOTE**: although most of the examples in this readme are Rails-specific, this gem could be used without Rails/ActiveSupport. ## The problem We need a way to handle different notifications _channel_ (mail, push) in one place. @@ -26,12 +28,13 @@ 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: +- 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? @@ -41,24 +44,24 @@ def after_some_action MyDelivery.with(user: user).notify(:some_action) end ``` -- better testability (see [Testing](#testing)). +- Better testability (see [Testing](#testing)). ## Installation Add this line to your application's Gemfile: ```ruby -gem 'active_delivery' +gem "active_delivery" ``` And then execute: ```sh -$ bundle +bundle ``` ## Usage The _Delivery_ class is used to trigger notifications. It describes how to notify a user (e.g., via email or push notification or both): @@ -93,16 +96,16 @@ ``` Delivery also supports _parameterized_ calling: ```ruby - PostsDelivery.with(user: user).notify(:published, post) +PostsDelivery.with(user: user).notify(:published, post) ``` The parameters could be accessed through the `params` instance method (e.g., to implement guard-like logic). -**NOTE**: When params are presents the parametrized mailer is used, i.e.: +**NOTE**: When params are presents the parameterized mailer is used, i.e.: ```ruby PostsMailer.with(user: user).published(post) ``` @@ -155,18 +158,19 @@ ```ruby it "delivers notification" do expect { subject }.to have_delivered_to(Community::EventsDelivery, :modified, event) .with(profile: profile) +end ``` You can also use such RSpec features as [compound expectations](https://relishapp.com/rspec/rspec-expectations/docs/compound-expectations) and [composed matchers](https://relishapp.com/rspec/rspec-expectations/v/3-8/docs/composing-matchers): ```ruby it "delivers to RSVPed members via .notify" do - expect { subject }. - to have_delivered_to(Community::EventsDelivery, :canceled, an_instance_of(event)).with( + expect { subject } + .to have_delivered_to(Community::EventsDelivery, :canceled, an_instance_of(event)).with( a_hash_including(profile: another_profile) ).and have_delivered_to(Community::EventsDelivery, :canceled, event).with( profile: profile ) end @@ -232,10 +236,9 @@ we call `EventDelivery.notify(:message_arrived, "ping-pong!")`. Line class has the following API: ```ruby - class PigeonLine < ActiveDelivery::Lines::Base # This method is used to infer sender class # `name` is the name of the delivery class def resolve_class(name) name.gsub(/Delivery$/, "Pigeon").safe_constantize