Skip to content

Commit 08fd870

Browse files
committed
extract the instrumentation key to be const and frozen string
1 parent af410c5 commit 08fd870

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/active_model/default_serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def initialize(object, options={})
1515
end
1616

1717
def as_json(options={})
18-
instrument('!serialize') do
18+
instrument do
1919
return [] if @object.nil? && @wrap_in_array
2020
hash = @object.as_json
2121
@wrap_in_array ? [hash] : hash

lib/active_model/serializable.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
module ActiveModel
44
module Serializable
5+
INSTRUMENTATION_KEY = "!serialize.active_model_serializers".freeze
6+
57
def self.included(base)
68
base.extend Utils
79
end
810

911
def as_json(options={})
10-
instrument('!serialize') do
12+
instrument do
1113
if root = options.fetch(:root, json_key)
1214
hash = { root => serializable_object(options) }
1315
hash.merge!(serializable_data)
@@ -19,9 +21,7 @@ def as_json(options={})
1921
end
2022

2123
def serializable_object_with_notification(options={})
22-
instrument('!serialize') do
23-
serializable_object(options)
24-
end
24+
instrument { serializable_object(options) }
2525
end
2626

2727
def serializable_data
@@ -51,9 +51,9 @@ def get_namespace
5151
modules[0..-2].join('::') if modules.size > 1
5252
end
5353

54-
def instrument(action, &block)
54+
def instrument(&block)
5555
payload = { serializer: self.class.name }
56-
ActiveSupport::Notifications.instrument("#{action}.active_model_serializers", payload, &block)
56+
ActiveSupport::Notifications.instrument(INSTRUMENTATION_KEY, payload, &block)
5757
end
5858
end
5959
end

0 commit comments

Comments
 (0)