File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ def initialize(object, options={})
15
15
end
16
16
17
17
def as_json ( options = { } )
18
- instrument ( '!serialize' ) do
18
+ instrument do
19
19
return [ ] if @object . nil? && @wrap_in_array
20
20
hash = @object . as_json
21
21
@wrap_in_array ? [ hash ] : hash
Original file line number Diff line number Diff line change 2
2
3
3
module ActiveModel
4
4
module Serializable
5
+ INSTRUMENTATION_KEY = "!serialize.active_model_serializers" . freeze
6
+
5
7
def self . included ( base )
6
8
base . extend Utils
7
9
end
8
10
9
11
def as_json ( options = { } )
10
- instrument ( '!serialize' ) do
12
+ instrument do
11
13
if root = options . fetch ( :root , json_key )
12
14
hash = { root => serializable_object ( options ) }
13
15
hash . merge! ( serializable_data )
@@ -19,9 +21,7 @@ def as_json(options={})
19
21
end
20
22
21
23
def serializable_object_with_notification ( options = { } )
22
- instrument ( '!serialize' ) do
23
- serializable_object ( options )
24
- end
24
+ instrument { serializable_object ( options ) }
25
25
end
26
26
27
27
def serializable_data
@@ -51,9 +51,9 @@ def get_namespace
51
51
modules [ 0 ..-2 ] . join ( '::' ) if modules . size > 1
52
52
end
53
53
54
- def instrument ( action , &block )
54
+ def instrument ( &block )
55
55
payload = { serializer : self . class . name }
56
- ActiveSupport ::Notifications . instrument ( " #{ action } .active_model_serializers" , payload , &block )
56
+ ActiveSupport ::Notifications . instrument ( INSTRUMENTATION_KEY , payload , &block )
57
57
end
58
58
end
59
59
end
You can’t perform that action at this time.
0 commit comments