mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Add AS::Notifications (thx @twinturbo)
This commit is contained in:
parent
6e2554d741
commit
2139a6d07a
@ -410,9 +410,13 @@ module ActiveModel
|
||||
# Returns a hash representation of the serializable
|
||||
# object without the root.
|
||||
def serializable_hash
|
||||
node = attributes
|
||||
include_associations!(node) if _embed
|
||||
node
|
||||
instrument(:serialize, :serializer => self.class.name) do
|
||||
node = attributes
|
||||
instrument :associations do
|
||||
include_associations!(node) if _embed
|
||||
end
|
||||
node
|
||||
end
|
||||
end
|
||||
|
||||
def include_associations!(node)
|
||||
@ -513,6 +517,12 @@ module ActiveModel
|
||||
end
|
||||
|
||||
alias :read_attribute_for_serialization :send
|
||||
|
||||
# Use ActiveSupport::Notifications to send events to external systems.
|
||||
# The event name is: name.class_name.serializer
|
||||
def instrument(name, payload = {}, &block)
|
||||
ActiveSupport::Notifications.instrument("#{name}.serializer", payload, &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
require "active_support"
|
||||
require "active_support/core_ext/string/inflections"
|
||||
require "active_support/notifications"
|
||||
require "active_model"
|
||||
require "active_model/serializer"
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user