Class: AppMap::Config::LookupPackage

Inherits:
Struct
  • Object
show all
Defined in:
lib/appmap/config.rb

Overview

Looks up a class and method in the config, to find the matching Package configuration. This class is only used after path_enabled? has returned ‘true`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clsObject

Returns the value of attribute cls

Returns:

  • (Object)

    the current value of cls



393
394
395
# File 'lib/appmap/config.rb', line 393

def cls
  @cls
end

#configObject

Returns the value of attribute config

Returns:

  • (Object)

    the current value of config



393
394
395
# File 'lib/appmap/config.rb', line 393

def config
  @config
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



393
394
395
# File 'lib/appmap/config.rb', line 393

def method
  @method
end

Instance Method Details

#packageObject



394
395
396
397
398
399
# File 'lib/appmap/config.rb', line 394

def package
  # Global "excludes" configuration can be used to ignore any class/method.
  return if config.never_hook?(cls, method)

  package_for_code_object || package_for_location
end

#package_for_code_objectObject

Hook a method which is specified by class and method name.



402
403
404
405
406
407
# File 'lib/appmap/config.rb', line 402

def package_for_code_object
  Array(config.hooked_methods[cls.name])
    .compact
    .find { |hook| hook.include_method?(method.name) }
    &.package
end

#package_for_locationObject

Hook a method which is specified by code location (i.e. path).



410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/appmap/config.rb', line 410

def package_for_location
  location = method.source_location
  location_file, = location
  return unless location_file

  location_file = AppMap::Util.normalize_path(location_file)
  config
    .packages
    .select { |pkg| pkg.path }
    .find do |pkg|
      (location_file.index(pkg.path) == 0) &&
        !pkg.exclude.find { |p| location_file.index(p) }
    end
end