This is an example of how I combine interaction/service classes with Wisper event broadcasting in Rails.
In this example, I show a UsersController#create
API, a corresponding service object, and all the test code/listeners to make it all happen.
The outcome is:
- Concepts in your system ("Signing up a user", "Creating an order") have a single entry point in your codebase, vs. making raw ActiveRecord calls to
object.save
in dozens of places. - Since your concept has one entry point (the service class), you can easily
grep
for usage of it. - Stupid easy to attach listeners to the service class
- All event listeners are very small and easily unit tested