Skip to content

Commit 9607b2a

Browse files
committed
refactor: Obtain the JSON from the response rather than the call
1 parent ff37a69 commit 9607b2a

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

lib/appmap/handler.rb

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
module AppMap
66
# Specific hook handler classes and general related utilities.
77
module Handler
8+
TEMPLATE_RENDER_FORMAT = 'appmap.handler.template.return_value_format'
89
TEMPLATE_RENDER_VALUE = 'appmap.handler.template.return_value'
910

1011
# Try to find handler module with a given name.

lib/appmap/handler/rails/render_handler.rb

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,23 @@ module Rails
66
class RenderHandler < AppMap::Handler::Function
77
def handle_call(receiver, args)
88
options, _ = args
9+
# TODO: :file, :xml
10+
# https://guides.rubyonrails.org/v5.1/layouts_and_rendering.html
911
if options[:json]
10-
Thread.current[TEMPLATE_RENDER_VALUE] = options[:json]
12+
Thread.current[TEMPLATE_RENDER_FORMAT] = :json
1113
end
1214

1315
super
1416
end
17+
18+
def handle_return(call_event_id, elapsed, return_value, exception)
19+
if Thread.current[TEMPLATE_RENDER_FORMAT] == :json
20+
Thread.current[TEMPLATE_RENDER_VALUE] = JSON.parse(return_value) rescue nil
21+
end
22+
Thread.current[TEMPLATE_RENDER_FORMAT] = nil
23+
24+
super
25+
end
1526
end
1627
end
1728
end

lib/appmap/handler/rails/request_handler.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def to_h
4747
value: self.class.display_string(val),
4848
object_id: val.__id__,
4949
}.tap do |message|
50-
AppMap::Event::MethodEvent.add_schema message, val, always: true
50+
AppMap::Event::MethodEvent.add_schema message, val
5151
end
5252
end
5353
end

spec/rails_recording_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def rails_versions
5555
'status_code' => 201,
5656
'headers' => hash_including('Content-Type' => 'application/json; charset=utf-8'),
5757
),
58-
'return_value' => hash_including('class' => 'User', 'object_id' => Integer, 'properties' => include({'name' => 'login', 'class' => 'String'})),
58+
'return_value' => hash_including('class' => 'Hash', 'object_id' => Integer, 'properties' => include({'name' => 'login', 'class' => 'String'})),
5959
)
6060
)
6161
end

0 commit comments

Comments
 (0)