author avatar

akshay

Fri Oct 12 2018

Rails has an ActiveSupport::Notifications module which is a part of its core instrumentation API. This API allows users to define hooks on events. With the ActiveSupport::Notifications you can instrument an event by simply calling instrument with a name, payload and a block. The notification will be sent after the block returns. Now all you need is to define subscribe method which consumes the event based on event name and you can define your on callback code here, sort of like a Pub/sub pattern.