12
12
module AppMap
13
13
class Config
14
14
# Specifies a code +path+ to be mapped.
15
+ #
15
16
# Options:
16
17
#
17
18
# * +gem+ may indicate a gem name that "owns" the path
18
- # * +package_name + can be used to make sure that the code is required so that it can be loaded. This is generally used with
19
+ # * +require_name + can be used to make sure that the code is required so that it can be loaded. This is generally used with
19
20
# builtins, or when the path to be required is not automatically required when bundler requires the gem.
20
21
# * +exclude+ can be used used to exclude sub-paths. Generally not used with +gem+.
21
22
# * +labels+ is used to apply labels to matching code. This is really only useful when the package will be applied to
22
23
# specific functions, via TargetMethods.
23
24
# * +shallow+ indicates shallow mapping, in which only the entrypoint to a gem is recorded.
24
- Package = Struct . new ( :path , :gem , :package_name , :exclude , :labels , :shallow ) do
25
+ Package = Struct . new ( :path , :gem , :require_name , :exclude , :labels , :shallow ) do
25
26
# This is for internal use only.
26
27
private_methods :gem
27
28
@@ -43,20 +44,20 @@ def shallow?
43
44
class << self
44
45
# Builds a package for a path, such as `app/models` in a Rails app. Generally corresponds to a `path:` entry
45
46
# in appmap.yml. Also used for mapping specific methods via TargetMethods.
46
- def build_from_path ( path , shallow : false , package_name : nil , exclude : [ ] , labels : [ ] )
47
- Package . new ( path , nil , package_name , exclude , labels , shallow )
47
+ def build_from_path ( path , shallow : false , require_name : nil , exclude : [ ] , labels : [ ] )
48
+ Package . new ( path , nil , require_name , exclude , labels , shallow )
48
49
end
49
50
50
51
# Builds a package for gem. Generally corresponds to a `gem:` entry in appmap.yml. Also used when mapping
51
52
# a builtin.
52
- def build_from_gem ( gem , shallow : true , package_name : nil , exclude : [ ] , labels : [ ] , optional : false , force : false )
53
+ def build_from_gem ( gem , shallow : true , require_name : nil , exclude : [ ] , labels : [ ] , optional : false , force : false )
53
54
if !force && %w[ method_source activesupport ] . member? ( gem )
54
55
warn "WARNING: #{ gem } cannot be AppMapped because it is a dependency of the appmap gem"
55
56
return
56
57
end
57
58
path = gem_path ( gem , optional )
58
59
if path
59
- Package . new ( path , gem , package_name , exclude , labels , shallow )
60
+ Package . new ( path , gem , require_name , exclude , labels , shallow )
60
61
else
61
62
AppMap ::Util . startup_message "#{ gem } is not available in the bundle"
62
63
end
@@ -81,7 +82,7 @@ def name
81
82
def to_h
82
83
{
83
84
path : path ,
84
- package_name : package_name ,
85
+ require_name : require_name ,
85
86
gem : gem ,
86
87
handler_class : handler_class . name ,
87
88
exclude : Util . blank? ( exclude ) ? nil : exclude ,
@@ -117,11 +118,11 @@ def to_h
117
118
# entry in appmap.yml. When the Config is initialized, each Function is converted into
118
119
# a Package and TargetMethods. It's called a Function rather than a Method, because Function
119
120
# is the AppMap terminology.
120
- Function = Struct . new ( :package , :cls , :labels , :function_names , :builtin , :package_name ) do # :nodoc:
121
+ Function = Struct . new ( :package , :cls , :labels , :function_names , :builtin , :require_name ) do # :nodoc:
121
122
def to_h
122
123
{
123
124
package : package ,
124
- package_name : package_name ,
125
+ require_name : require_name ,
125
126
class : cls ,
126
127
labels : labels ,
127
128
functions : function_names . map ( &:to_sym ) ,
@@ -138,9 +139,9 @@ def to_h
138
139
private_constant :MethodHook
139
140
140
141
class << self
141
- def package_hooks ( gem_name , methods , handler_class : nil , package_name : nil )
142
+ def package_hooks ( gem_name , methods , handler_class : nil , require_name : nil )
142
143
Array ( methods ) . map do |method |
143
- package = Package . build_from_gem ( gem_name , package_name : package_name , labels : method . labels , shallow : false , optional : true )
144
+ package = Package . build_from_gem ( gem_name , require_name : require_name , labels : method . labels , shallow : false , optional : true )
144
145
next unless package
145
146
146
147
package . handler_class = handler_class if handler_class
@@ -164,14 +165,14 @@ def method_hook(cls, method_names, labels)
164
165
method_hook ( 'ActionView::PartialRenderer' , :render , %w[ mvc.view ] )
165
166
] ,
166
167
handler_class : AppMap ::Handler ::Rails ::Template ::RenderHandler ,
167
- package_name : 'action_view'
168
+ require_name : 'action_view'
168
169
) ,
169
170
package_hooks ( 'actionview' ,
170
171
[
171
172
method_hook ( 'ActionView::Resolver' , %i[ find_all find_all_anywhere ] , %w[ mvc.template.resolver ] )
172
173
] ,
173
174
handler_class : AppMap ::Handler ::Rails ::Template ::ResolverHandler ,
174
- package_name : 'action_view'
175
+ require_name : 'action_view'
175
176
) ,
176
177
package_hooks ( 'actionpack' ,
177
178
[
@@ -181,7 +182,7 @@ def method_hook(cls, method_names, labels)
181
182
method_hook ( 'ActionDispatch::Cookies::CookieJar' , %i[ []= clear update delete recycle ] , %w[ http.session.write ] ) ,
182
183
method_hook ( 'ActionDispatch::Cookies::EncryptedCookieJar' , %i[ []= clear update delete recycle ] , %w[ http.cookie crypto.encrypt ] )
183
184
] ,
184
- package_name : 'action_dispatch'
185
+ require_name : 'action_dispatch'
185
186
) ,
186
187
package_hooks ( 'cancancan' ,
187
188
[
@@ -193,11 +194,11 @@ def method_hook(cls, method_names, labels)
193
194
[
194
195
method_hook ( 'ActionController::Instrumentation' , %i[ process_action send_file send_data redirect_to ] , %w[ mvc.controller ] )
195
196
] ,
196
- package_name : 'action_controller'
197
+ require_name : 'action_controller'
197
198
)
198
199
] . flatten . freeze
199
200
200
- OPENSSL_PACKAGES = -> ( labels ) { Package . build_from_path ( 'openssl' , package_name : 'openssl' , labels : labels ) }
201
+ OPENSSL_PACKAGES = -> ( labels ) { Package . build_from_path ( 'openssl' , require_name : 'openssl' , labels : labels ) }
201
202
202
203
# Hook functions which are builtin to Ruby. Because they are builtins, they may be loaded before appmap.
203
204
# Therefore, we can't rely on TracePoint to report the loading of this code.
@@ -210,25 +211,25 @@ def method_hook(cls, method_names, labels)
210
211
TargetMethods . new ( %i[ decrypt ] , OPENSSL_PACKAGES . ( %w[ crypto.decrypt ] ) )
211
212
] ,
212
213
'ActiveSupport::Callbacks::CallbackSequence' => [
213
- TargetMethods . new ( :invoke_before , Package . build_from_gem ( 'activesupport' , force : true , package_name : 'active_support' , labels : %w[ mvc.before_action ] ) ) ,
214
- TargetMethods . new ( :invoke_after , Package . build_from_gem ( 'activesupport' , force : true , package_name : 'active_support' , labels : %w[ mvc.after_action ] ) ) ,
214
+ TargetMethods . new ( :invoke_before , Package . build_from_gem ( 'activesupport' , force : true , require_name : 'active_support' , labels : %w[ mvc.before_action ] ) ) ,
215
+ TargetMethods . new ( :invoke_after , Package . build_from_gem ( 'activesupport' , force : true , require_name : 'active_support' , labels : %w[ mvc.after_action ] ) ) ,
215
216
] ,
216
- 'ActiveSupport::SecurityUtils' => TargetMethods . new ( :secure_compare , Package . build_from_gem ( 'activesupport' , force : true , package_name : 'active_support/security_utils' , labels : %w[ crypto.secure_compare ] ) ) ,
217
+ 'ActiveSupport::SecurityUtils' => TargetMethods . new ( :secure_compare , Package . build_from_gem ( 'activesupport' , force : true , require_name : 'active_support/security_utils' , labels : %w[ crypto.secure_compare ] ) ) ,
217
218
'OpenSSL::X509::Certificate' => TargetMethods . new ( :sign , OPENSSL_PACKAGES . ( %w[ crypto.x509 ] ) ) ,
218
- 'Net::HTTP' => TargetMethods . new ( :request , Package . build_from_path ( 'net/http' , package_name : 'net/http' , labels : %w[ protocol.http ] ) . tap do |package |
219
+ 'Net::HTTP' => TargetMethods . new ( :request , Package . build_from_path ( 'net/http' , require_name : 'net/http' , labels : %w[ protocol.http ] ) . tap do |package |
219
220
package . handler_class = AppMap ::Handler ::NetHTTP
220
221
end ) ,
221
- 'Net::SMTP' => TargetMethods . new ( :send , Package . build_from_path ( 'net/smtp' , package_name : 'net/smtp' , labels : %w[ protocol.email.smtp ] ) ) ,
222
- 'Net::POP3' => TargetMethods . new ( :mails , Package . build_from_path ( 'net/pop3' , package_name : 'net/pop' , labels : %w[ protocol.email.pop ] ) ) ,
222
+ 'Net::SMTP' => TargetMethods . new ( :send , Package . build_from_path ( 'net/smtp' , require_name : 'net/smtp' , labels : %w[ protocol.email.smtp ] ) ) ,
223
+ 'Net::POP3' => TargetMethods . new ( :mails , Package . build_from_path ( 'net/pop3' , require_name : 'net/pop' , labels : %w[ protocol.email.pop ] ) ) ,
223
224
# This is happening: Method send_command not found on Net::IMAP
224
- # 'Net::IMAP' => TargetMethods.new(:send_command, Package.build_from_path('net/imap', package_name : 'net/imap', labels: %w[protocol.email.imap])),
225
+ # 'Net::IMAP' => TargetMethods.new(:send_command, Package.build_from_path('net/imap', require_name : 'net/imap', labels: %w[protocol.email.imap])),
225
226
# 'Marshal' => TargetMethods.new(%i[dump load], Package.build_from_path('marshal', labels: %w[format.marshal])),
226
227
'Psych' => [
227
- TargetMethods . new ( %i[ load load_stream parse parse_stream ] , Package . build_from_path ( 'yaml' , package_name : 'psych' , labels : %w[ format.yaml.parse ] ) ) ,
228
- TargetMethods . new ( %i[ dump dump_stream ] , Package . build_from_path ( 'yaml' , package_name : 'psych' , labels : %w[ format.yaml.generate ] ) ) ,
228
+ TargetMethods . new ( %i[ load load_stream parse parse_stream ] , Package . build_from_path ( 'yaml' , require_name : 'psych' , labels : %w[ format.yaml.parse ] ) ) ,
229
+ TargetMethods . new ( %i[ dump dump_stream ] , Package . build_from_path ( 'yaml' , require_name : 'psych' , labels : %w[ format.yaml.generate ] ) ) ,
229
230
] ,
230
- 'JSON::Ext::Parser' => TargetMethods . new ( :parse , Package . build_from_path ( 'json' , package_name : 'json' , labels : %w[ format.json.parse ] ) ) ,
231
- 'JSON::Ext::Generator::State' => TargetMethods . new ( :generate , Package . build_from_path ( 'json' , package_name : 'json' , labels : %w[ format.json.generate ] ) ) ,
231
+ 'JSON::Ext::Parser' => TargetMethods . new ( :parse , Package . build_from_path ( 'json' , require_name : 'json' , labels : %w[ format.json.parse ] ) ) ,
232
+ 'JSON::Ext::Generator::State' => TargetMethods . new ( :generate , Package . build_from_path ( 'json' , require_name : 'json' , labels : %w[ format.json.generate ] ) ) ,
232
233
} . freeze
233
234
234
235
attr_reader :name , :appmap_dir , :packages , :exclude , :swagger_config , :depends_config , :hooked_methods , :builtin_hooks
@@ -256,8 +257,8 @@ def initialize(name,
256
257
functions . each do |func |
257
258
package_options = { }
258
259
package_options [ :labels ] = func . labels if func . labels
259
- package_options [ :package_name ] = func . package_name
260
- package_options [ :package_name ] ||= func . package if func . builtin
260
+ package_options [ :require_name ] = func . require_name
261
+ package_options [ :require_name ] ||= func . package if func . builtin
261
262
hook = TargetMethods . new ( func . function_names , Package . build_from_path ( func . package , **package_options ) )
262
263
if func . builtin
263
264
@builtin_hooks [ func . cls ] ||= [ ]
@@ -366,7 +367,11 @@ def load(config_data)
366
367
shallow = package [ 'shallow' ]
367
368
# shallow is true by default for gems
368
369
shallow = true if shallow . nil?
369
- Package . build_from_gem ( gem , package_name : package [ 'package' ] , exclude : package [ 'exclude' ] || [ ] , shallow : shallow )
370
+
371
+ require_name = \
372
+ package [ 'package' ] || #deprecated
373
+ package [ 'require_name' ]
374
+ Package . build_from_gem ( gem , require_name : require_name , exclude : package [ 'exclude' ] || [ ] , shallow : shallow )
370
375
else
371
376
Package . build_from_path ( path , exclude : package [ 'exclude' ] || [ ] , shallow : package [ 'shallow' ] )
372
377
end
0 commit comments