Understand Bullet's internal control flow
mainBullet integrates with Rails by extending ActiveRecord (and ActiveController for Rails 2.x) or by inserting itself as Rack middleware in Rails 3+.
The request lifecycle follows these steps:
Bullet.start_requestis called, resetting detectors and clearing the notification collector.- Rails handles the request;
ActiveRecordextensions triggerDetectorcallbacks. Detectorsidentify noteworthy events and createNotificationinstances, which are stored in the mainBulletmodule's collector.- After the request is handled, Bullet iterates over each notification using a
Presenterto generate inline messages appended to the response body. - Bullet generates out-of-channel messages for each notification.
Bulletcallsend_requestfor each detector.- The cycle repeats for the next request.