extract the instrumentation key to be const and frozen string

This commit is contained in:
Yosi Attias 2017-03-24 15:16:01 +03:00
parent af410c54e6
commit 08fd8705f3
2 changed files with 7 additions and 7 deletions

View File

@ -15,7 +15,7 @@ module ActiveModel
end
def as_json(options={})
instrument('!serialize') do
instrument do
return [] if @object.nil? && @wrap_in_array
hash = @object.as_json
@wrap_in_array ? [hash] : hash

View File

@ -2,12 +2,14 @@ require 'active_model/serializable/utils'
module ActiveModel
module Serializable
INSTRUMENTATION_KEY = "!serialize.active_model_serializers".freeze
def self.included(base)
base.extend Utils
end
def as_json(options={})
instrument('!serialize') do
instrument do
if root = options.fetch(:root, json_key)
hash = { root => serializable_object(options) }
hash.merge!(serializable_data)
@ -19,9 +21,7 @@ module ActiveModel
end
def serializable_object_with_notification(options={})
instrument('!serialize') do
serializable_object(options)
end
instrument { serializable_object(options) }
end
def serializable_data
@ -51,9 +51,9 @@ module ActiveModel
modules[0..-2].join('::') if modules.size > 1
end
def instrument(action, &block)
def instrument(&block)
payload = { serializer: self.class.name }
ActiveSupport::Notifications.instrument("#{action}.active_model_serializers", payload, &block)
ActiveSupport::Notifications.instrument(INSTRUMENTATION_KEY, payload, &block)
end
end
end