Reader small image

You're reading from  Layered Design for Ruby on Rails Applications

Product typeBook
Published inAug 2023
Reading LevelIntermediate
PublisherPackt
ISBN-139781801813785
Edition1st Edition
Languages
Right arrow
Author (1)
Vladimir Dementyev
Vladimir Dementyev
author image
Vladimir Dementyev

Vladimir Dementyev has been working on web applications for more than 10 years and launched his first Ruby on Rails project back in 2014. Since then, he has been working on a dozen of Rails web applications, used by hundreds of millions of customers, monolithic or component-based, following the Rails way or trying to swim against the current. He has been an active member of Rails open-source community since 2015, becoming a regular Rails contributor, a RailsConf speaker, and the author of dozens of gems, including AnyCable, TestProf, and Action Policy to name a few. For his work on the Ruby Next project, the author got the Fukuoka Ruby Award for outstanding performance in 2021. Currently, he's leading the backend developers' team at Evil Martians, helping dozens of web projects around the world build better software.
Read more about Vladimir Dementyev

Right arrow

Extracting notifications layer

What is the notifications layer? We can define it as an abstraction layer responsible for orchestrating user notifications. The responsibilities of this layer are as listed here:

  • Deciding which communication channels to use for a given notification and a user
  • Preparing notification payloads (email subjects and bodies, SMS contents, and so on)
  • Interacting with delivery services (mailing servers, third-party APIs, and so on)

A notifications layer may be comprised of multiple abstractions or sub-layers. For example, we still can (and should) use Action Mailer for emails, but we need a higher-level entry-point abstraction, which would delegate the specific channel logic to lower abstractions.

As the first step toward a new abstraction, let’s refactor our Post::Publish class using a simple object (or class) extraction technique.

Ad hoc abstraction

Let’s start by moving the #notify_subscribers method implementation...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Layered Design for Ruby on Rails Applications
Published in: Aug 2023Publisher: PacktISBN-13: 9781801813785

Author (1)

author image
Vladimir Dementyev

Vladimir Dementyev has been working on web applications for more than 10 years and launched his first Ruby on Rails project back in 2014. Since then, he has been working on a dozen of Rails web applications, used by hundreds of millions of customers, monolithic or component-based, following the Rails way or trying to swim against the current. He has been an active member of Rails open-source community since 2015, becoming a regular Rails contributor, a RailsConf speaker, and the author of dozens of gems, including AnyCable, TestProf, and Action Policy to name a few. For his work on the Ruby Next project, the author got the Fukuoka Ruby Award for outstanding performance in 2021. Currently, he's leading the backend developers' team at Evil Martians, helping dozens of web projects around the world build better software.
Read more about Vladimir Dementyev