Class: AppMap::Config
- Inherits:
-
Object
- Object
- AppMap::Config
- Defined in:
- lib/appmap/config.rb
Constant Summary collapse
- HOOKED_METHODS =
Methods that should always be hooked, with their containing package and labels that should be applied to them.
{ 'ActiveSupport::SecurityUtils' => { secure_compare: Package.new('active_support', nil, nil, ['security']) } }
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#packages ⇒ Object
readonly
Returns the value of attribute packages.
Class Method Summary collapse
-
.load(config_data) ⇒ Object
Loads configuration from a Hash.
-
.load_from_file(config_file_name) ⇒ Object
Loads configuration data from a file, specified by the file name.
Instance Method Summary collapse
- #always_hook?(defined_class, method_name) ⇒ Boolean
- #find_hooked_class(defined_class) ⇒ Object
- #find_hooked_method(defined_class, method_name) ⇒ Object
- #included_by_location?(method) ⇒ Boolean
-
#initialize(name, packages = []) ⇒ Config
constructor
A new instance of Config.
- #package_for_method(method) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name, packages = []) ⇒ Config
Returns a new instance of Config.
29 30 31 32 |
# File 'lib/appmap/config.rb', line 29 def initialize(name, packages = []) @name = name @packages = packages end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
28 29 30 |
# File 'lib/appmap/config.rb', line 28 def name @name end |
#packages ⇒ Object (readonly)
Returns the value of attribute packages.
28 29 30 |
# File 'lib/appmap/config.rb', line 28 def packages @packages end |
Class Method Details
.load(config_data) ⇒ Object
Loads configuration from a Hash.
42 43 44 45 46 47 |
# File 'lib/appmap/config.rb', line 42 def load(config_data) packages = (config_data['packages'] || []).map do |package| Package.new(package['path'], nil, package['exclude'] || []) end Config.new config_data['name'], packages end |
.load_from_file(config_file_name) ⇒ Object
Loads configuration data from a file, specified by the file name.
36 37 38 39 |
# File 'lib/appmap/config.rb', line 36 def load_from_file(config_file_name) require 'yaml' load YAML.safe_load(::File.read(config_file_name)) end |
Instance Method Details
#always_hook?(defined_class, method_name) ⇒ Boolean
77 78 79 |
# File 'lib/appmap/config.rb', line 77 def always_hook?(defined_class, method_name) !!find_hooked_method(defined_class, method_name) end |
#find_hooked_class(defined_class) ⇒ Object
85 86 87 |
# File 'lib/appmap/config.rb', line 85 def find_hooked_class(defined_class) HOOKED_METHODS[defined_class] || {} end |
#find_hooked_method(defined_class, method_name) ⇒ Object
81 82 83 |
# File 'lib/appmap/config.rb', line 81 def find_hooked_method(defined_class, method_name) find_hooked_class(defined_class)[method_name] end |
#included_by_location?(method) ⇒ Boolean
73 74 75 |
# File 'lib/appmap/config.rb', line 73 def included_by_location?(method) !!package_for_method(method) end |
#package_for_method(method) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/appmap/config.rb', line 57 def package_for_method(method) defined_class, _, method_name = Hook.qualify_method_name(method) hooked_method = find_hooked_method(defined_class, method_name) return hooked_method if hooked_method location = method.source_location location_file, = location return unless location_file location_file = location_file[Dir.pwd.length + 1..-1] if location_file.index(Dir.pwd) == 0 packages.find do |pkg| (location_file.index(pkg.path) == 0) && !pkg.exclude.find { |p| location_file.index(p) } end end |
#to_h ⇒ Object
50 51 52 53 54 55 |
# File 'lib/appmap/config.rb', line 50 def to_h { name: name, packages: packages.map(&:to_h) } end |