Skip to content

Commit f4d5b11

Browse files
committed
fix: Method objects must support eql? and hash to ensure they are unique in a Set
1 parent 07967a1 commit f4d5b11

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

lib/appmap/handler/rails/template.rb

+19-5
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,30 @@ class Template
1414
# The class name is generated from the template path. The package name is
1515
# 'app/views', and the method name is 'render'. The source location of the method
1616
# is, of course, the path to the view template.
17-
TemplateMethod = Struct.new(:path) do
18-
private_instance_methods :path
17+
class TemplateMethod
1918
attr_reader :class_name
20-
19+
20+
attr_reader :path
21+
private_instance_methods :path
22+
2123
def initialize(path)
22-
super
24+
@path = path
2325

2426
@class_name = path.parameterize.underscore
2527
end
26-
28+
29+
def id
30+
[ package, path, name ]
31+
end
32+
33+
def hash
34+
id.hash
35+
end
36+
37+
def eql?(other)
38+
other.is_a?(TemplateMethod) && id.eql?(other.id)
39+
end
40+
2741
def package
2842
'app/views'
2943
end

lib/appmap/trace.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
module AppMap
44
module Trace
5-
class RubyMethod
5+
class RubyMethod < SimpleDelegator
66
attr_reader :class_name, :static
77

88
def initialize(package, class_name, method, static)
9+
super(method)
10+
911
@package = package
1012
@class_name = class_name
1113
@method = method
@@ -111,7 +113,7 @@ def record_event(event, package: nil, defined_class: nil, method: nil)
111113
@last_package_for_thread[Thread.current.object_id] = package if package
112114
@events << event
113115
static = event.static if event.respond_to?(:static)
114-
@methods << Trace::RubyMethod.new(package, defined_class, method, static) \
116+
record_method Trace::RubyMethod.new(package, defined_class, method, static) \
115117
if package && defined_class && method && (event.event == :call)
116118
end
117119

0 commit comments

Comments
 (0)