Update for review per maurogeorge feedback

This commit is contained in:
Benjamin Fleischer
2015-11-10 03:21:40 -06:00
parent b36cc42f03
commit d1c44c719d
5 changed files with 118 additions and 89 deletions

View File

@@ -1,7 +1,8 @@
# Instrumentation
ActiveModelSerializers uses the ActiveSupport::Notification API, which
allows for subscribing to events, such as for logging.
ActiveModelSerializers uses the
[ActiveSupport::Notification API](http://guides.rubyonrails.org/active_support_instrumentation.html#subscribing-to-an-event),
which allows for subscribing to events, such as for logging.
## Events
@@ -17,3 +18,20 @@ Payload (example):
adapter: ActiveModel::Serializer::Adapter::Attributes
}
```
Subscribing:
```ruby
ActiveSupport::Notifications.subscribe 'render.active_model_serializers' do |name, started, finished, unique_id, data|
# whatever
end
ActiveSupport::Notifications.subscribe 'render.active_model_serializers' do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
# event.payload
# whatever
end
## [LogSubscriber](http://api.rubyonrails.org/classes/ActiveSupport/LogSubscriber.html)
ActiveModelSerializers includes an `ActiveModelSerializers::LogSubscriber` that attaches to
`render.active_model_serializers`.