mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Merge pull request #2080 from yosiat/instrumentation-cleanup
[0.9] Removing `instrumentation_keys` in order to fix the payload
This commit is contained in:
@@ -64,10 +64,5 @@ module ActiveModel
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def instrumentation_keys
|
||||
[:object, :scope, :root, :meta_key, :meta, :each_serializer, :resource_name, :key_format, :context]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,18 +15,14 @@ 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
|
||||
end
|
||||
end
|
||||
|
||||
alias serializable_hash as_json
|
||||
alias serializable_object as_json
|
||||
|
||||
private
|
||||
def instrumentation_keys
|
||||
[:object, :wrap_in_array]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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,16 +51,9 @@ module ActiveModel
|
||||
modules[0..-2].join('::') if modules.size > 1
|
||||
end
|
||||
|
||||
def instrument(action, &block)
|
||||
payload = instrumentation_keys.inject({ serializer: self.class.name }) do |payload, key|
|
||||
payload[:payload] = self.instance_variable_get(:"@#{key}")
|
||||
payload
|
||||
end
|
||||
ActiveSupport::Notifications.instrument("#{action}.active_model_serializers", payload, &block)
|
||||
end
|
||||
|
||||
def instrumentation_keys
|
||||
[:object, :scope, :root, :meta_key, :meta, :wrap_in_array, :only, :except, :key_format]
|
||||
def instrument(&block)
|
||||
payload = { serializer: self.class.name }
|
||||
ActiveSupport::Notifications.instrument(INSTRUMENTATION_KEY, payload, &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user