Add AS::Notifications (thx @twinturbo)

This commit is contained in:
twinturbo 2012-04-26 08:39:59 -05:00 committed by Yehuda Katz
parent 6e2554d741
commit 2139a6d07a
2 changed files with 14 additions and 3 deletions

View File

@ -410,10 +410,14 @@ module ActiveModel
# Returns a hash representation of the serializable
# object without the root.
def serializable_hash
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)
_associations.each do |attr, klass|
@ -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

View File

@ -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"