Class: AppMap::Config::Package
Overview
Specifies a logical code package be mapped. This can be a project source folder, a Gem, or a builtin.
Options:
-
path
indicates a relative path to a code folder. -
gem
may indicate a gem name that “owns” the path -
require_name
can be used to make sure that the code is required so that it can be loaded. This is generally used with builtins, or when the path to be required is not automatically required when bundler requires the gem. -
exclude
can be used used to exclude sub-paths. Generally not used withgem
. -
labels
is used to apply labels to matching code. This is really only useful when the package will be applied to specific functions, via TargetMethods. -
shallow
indicates shallow mapping, in which only the entrypoint to a gem is recorded.
Instance Attribute Summary collapse
-
#builtin ⇒ Object
Returns the value of attribute builtin.
-
#exclude ⇒ Object
Returns the value of attribute exclude.
-
#gem ⇒ Object
Returns the value of attribute gem.
- #handler_class ⇒ Object
-
#labels ⇒ Object
Returns the value of attribute labels.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#require_name ⇒ Object
Returns the value of attribute require_name.
-
#shallow ⇒ Object
Returns the value of attribute shallow.
Class Method Summary collapse
- .build_from_builtin(path, shallow: false, require_name: nil, exclude: [], labels: []) ⇒ Object
-
.build_from_gem(gem, shallow: true, require_name: nil, exclude: [], labels: [], optional: false, force: false) ⇒ Object
Builds a package for gem.
-
.build_from_path(path, shallow: false, require_name: nil, exclude: [], labels: []) ⇒ Object
Builds a package for a path, such as ‘app/models` in a Rails app.
Instance Method Summary collapse
- #record_around? ⇒ Boolean
-
#shallow? ⇒ Boolean
Indicates that only the entry points to a package will be recorded.
-
#subpackage(location, config) ⇒ Object
Clones this package into a sub-package, if needed.
- #to_h ⇒ Object
Instance Attribute Details
#builtin ⇒ Object
Returns the value of attribute builtin
38 39 40 |
# File 'lib/appmap/config.rb', line 38 def builtin @builtin end |
#exclude ⇒ Object
Returns the value of attribute exclude
38 39 40 |
# File 'lib/appmap/config.rb', line 38 def exclude @exclude end |
#gem ⇒ Object
Returns the value of attribute gem
38 39 40 |
# File 'lib/appmap/config.rb', line 38 def gem @gem end |
#handler_class ⇒ Object
49 50 51 52 |
# File 'lib/appmap/config.rb', line 49 def handler_class require "appmap/handler/function_handler" @handler_class || AppMap::Handler::FunctionHandler end |
#labels ⇒ Object
Returns the value of attribute labels
38 39 40 |
# File 'lib/appmap/config.rb', line 38 def labels @labels end |
#name ⇒ Object
Returns the value of attribute name
38 39 40 |
# File 'lib/appmap/config.rb', line 38 def name @name end |
#path ⇒ Object
Returns the value of attribute path
38 39 40 |
# File 'lib/appmap/config.rb', line 38 def path @path end |
#require_name ⇒ Object
Returns the value of attribute require_name
38 39 40 |
# File 'lib/appmap/config.rb', line 38 def require_name @require_name end |
#shallow ⇒ Object
Returns the value of attribute shallow
38 39 40 |
# File 'lib/appmap/config.rb', line 38 def shallow @shallow end |
Class Method Details
.build_from_builtin(path, shallow: false, require_name: nil, exclude: [], labels: []) ⇒ Object
83 84 85 |
# File 'lib/appmap/config.rb', line 83 def build_from_builtin(path, shallow: false, require_name: nil, exclude: [], labels: []) Package.new(path, path, nil, require_name, exclude, labels, shallow, true) end |
.build_from_gem(gem, shallow: true, require_name: nil, exclude: [], labels: [], optional: false, force: false) ⇒ Object
Builds a package for gem. Generally corresponds to a ‘gem:` entry in appmap.yml. Also used when mapping a builtin.
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/appmap/config.rb', line 89 def build_from_gem(gem, shallow: true, require_name: nil, exclude: [], labels: [], optional: false, force: false) if !force && %w[method_source].member?(gem) warn "WARNING: #{gem} cannot be AppMapped because it is a dependency of the appmap gem" return end path = gem_path(gem, optional) if path Package.new(gem, path, gem, require_name, exclude, labels, shallow) else AppMap::Util. "#{gem} is not available in the bundle" end end |
.build_from_path(path, shallow: false, require_name: nil, exclude: [], labels: []) ⇒ Object
Builds a package for a path, such as ‘app/models` in a Rails app. Generally corresponds to a `path:` entry in appmap.yml. Also used for mapping specific methods via TargetMethods.
79 80 81 |
# File 'lib/appmap/config.rb', line 79 def build_from_path(path, shallow: false, require_name: nil, exclude: [], labels: []) Package.new(path, path, nil, require_name, exclude, labels, shallow) end |
Instance Method Details
#record_around? ⇒ Boolean
45 46 47 |
# File 'lib/appmap/config.rb', line 45 def record_around? RECORD_AROUND_LABELS.find { |label| labels&.member?(label) } end |
#shallow? ⇒ Boolean
Indicates that only the entry points to a package will be recorded. Once the code has entered a package, subsequent calls within the package will not be recorded unless the code leaves the package and re-enters it.
57 58 59 |
# File 'lib/appmap/config.rb', line 57 def shallow? shallow end |
#subpackage(location, config) ⇒ Object
Clones this package into a sub-package, if needed. For example, suppose the appmap.yml specifies package ‘app/models`. If some code in `app/models/dao/user.rb` is mapped, it will be associated with a sub-package `app/models/dao`.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/appmap/config.rb', line 65 def subpackage(location, config) return self if gem path = location.split("/")[0...-1].join("/") clone.tap do |pkg| pkg.name = path pkg.path = path config.packages << pkg end end |
#to_h ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/appmap/config.rb', line 114 def to_h { name: name, path: path, gem: gem, require_name: require_name, handler_class: handler_class ? handler_class.name : nil, exclude: Util.blank?(exclude) ? nil : exclude, labels: Util.blank?(labels) ? nil : labels, shallow: shallow.nil? ? nil : shallow }.compact end |