@@ -60,66 +60,19 @@ def display_string(value)
60
60
final ? value_string : encode_display_string ( value_string )
61
61
end
62
62
63
- def add_schema ( param , value , always : false )
64
- param [ :size ] = value . size if value . respond_to? ( :size ) && value . is_a? ( Enumerable )
65
-
66
- return unless always || AppMap . parameter_schema?
67
-
68
- if value . blank? || value . is_a? ( String )
69
- # pass
70
- elsif value . is_a? ( Enumerable )
71
- if value . is_a? ( Hash )
72
- param [ :properties ] = object_properties ( value )
63
+ def add_schema ( param , value )
64
+ begin
65
+ if value . respond_to? ( :keys )
66
+ param [ :properties ] = value . keys . map { |key | { name : key , class : best_class_name ( value [ key ] ) } }
73
67
elsif value . respond_to? ( :first ) && value . first
74
- param [ :properties ] = object_properties ( value . first )
75
- end
76
- else
77
- json_value = try_as_json ( value ) || try_to_json ( value )
78
- if value != json_value
79
- add_schema param , json_value , always : always
68
+ if value . first != value
69
+ add_schema param , value . first
70
+ end
80
71
end
81
- end
82
- end
83
-
84
- def try_as_json ( value )
85
- value . respond_to? ( :as_json ) && value . as_json
86
- end
87
- private_instance_methods :try_as_json
88
-
89
- def try_to_json ( value )
90
- value . respond_to? ( :to_json ) && JSON . parse ( value . to_json )
91
- end
92
- private_instance_methods :try_to_json
93
-
94
- def object_properties ( hash )
95
- hash = hash . attributes if hash . respond_to? ( :attributes )
96
-
97
- hash = try_to_h ( hash )
98
-
99
- return unless hash . respond_to? ( :each_with_object )
100
-
101
- hash . map { |k , v | { name : k , class : v . class . name } }
102
- rescue
103
- warn $!
104
- end
105
-
106
- def try_to_h ( value )
107
- return value unless value . respond_to? ( :to_h )
108
-
109
- # Includes such bad actors as Psych::Nodes::Scalar.
110
- # Also don't try and hashifiy list-ish things.
111
- @unhashifiable_classes ||= Set . new ( [ Array , Set ] )
112
-
113
- return value if @unhashifiable_classes . include? ( value . class )
114
-
115
- begin
116
- value . to_h
117
72
rescue
118
- # warn "#{value.class}#to_h failed: #{$!.message}"
119
- @unhashifiable_classes << value . class
73
+ warn "Error in add_schema(#{ value . class } )" , $!
120
74
end
121
75
end
122
- private_instance_methods :try_to_h
123
76
124
77
# Heuristic for dynamically defined class whose name can be nil
125
78
def best_class_name ( value )
@@ -271,7 +224,7 @@ def build_from_invocation(defined_class, method, receiver, arguments, event: Met
271
224
value : display_string ( value ) ,
272
225
kind : param_type
273
226
} . tap do |param |
274
- add_schema param , value
227
+ param [ :size ] = value . size if value . respond_to? ( :size ) && value . is_a? ( Enumerable )
275
228
end
276
229
end
277
230
event . receiver = {
@@ -337,7 +290,7 @@ def build_from_invocation(parent_id, return_value, exception, elapsed: nil, even
337
290
object_id : return_value . __id__
338
291
} . tap do |param |
339
292
param [ :size ] = return_value . size if return_value . respond_to? ( :size ) && return_value . is_a? ( Enumerable )
340
- add_schema param , return_value , always : parameter_schema
293
+ add_schema param , return_value if parameter_schema && ! exception
341
294
end
342
295
end
343
296
if exception
0 commit comments