Class: AppMap::Config
- Inherits:
-
Object
- Object
- AppMap::Config
- Defined in:
- lib/appmap/config.rb
Defined Under Namespace
Constant Summary collapse
- OPENSSL_PACKAGES =
Package.build_from_path('openssl', package_name: 'openssl', labels: %w[security crypto])
- HOOKED_METHODS =
Methods that should always be hooked, with their containing package and labels that should be applied to them.
{ 'ActiveSupport::SecurityUtils' => Hook.new(:secure_compare, Package.build_from_path('active_support', labels: %w[provider.secure_compare])), 'ActionView::Renderer' => Hook.new(:render, Package.build_from_path('action_view', labels: %w[mvc.view])), 'ActionDispatch::Cookies::CookieJar' => Hook.new(%i[[]= clear update delete recycle], Package.build_from_path('action_pack', labels: %w[provider.http.cookie])), 'ActionDispatch::Cookies::EncryptedCookieJar' => Hook.new(%i[[]=], Package.build_from_path('action_pack', labels: %w[provider.http.cookie crypto])), 'CanCan::ControllerAdditions' => Hook.new(%i[authorize! can? cannot?], Package.build_from_path('cancancan', labels: %w[provider.authorization])), 'CanCan::Ability' => Hook.new(%i[authorize!], Package.build_from_path('cancancan', labels: %w[provider.authorization])), }.freeze
- BUILTIN_METHODS =
{ 'OpenSSL::PKey::PKey' => Hook.new(:sign, OPENSSL_PACKAGES), 'OpenSSL::X509::Request' => Hook.new(%i[sign verify], OPENSSL_PACKAGES), 'OpenSSL::PKCS5' => Hook.new(%i[pbkdf2_hmac_sha1 pbkdf2_hmac], OPENSSL_PACKAGES), 'OpenSSL::Cipher' => Hook.new(%i[encrypt decrypt final], OPENSSL_PACKAGES), 'OpenSSL::X509::Certificate' => Hook.new(:sign, OPENSSL_PACKAGES), 'Net::HTTP' => Hook.new(:request, Package.build_from_path('net/http', package_name: 'net/http', labels: %w[protocol.http io])), 'Net::SMTP' => Hook.new(:send, Package.build_from_path('net/smtp', package_name: 'net/smtp', labels: %w[protocol.smtp protocol.email io])), 'Net::POP3' => Hook.new(:mails, Package.build_from_path('net/pop3', package_name: 'net/pop', labels: %w[protocol.pop protocol.email io])), 'Net::IMAP' => Hook.new(:send_command, Package.build_from_path('net/imap', package_name: 'net/imap', labels: %w[protocol.imap protocol.email io])), 'Marshal' => Hook.new(%i[dump load], Package.build_from_path('marshal', labels: %w[format.marshal provider.serialization])), 'Psych' => Hook.new(%i[dump dump_stream load load_stream parse parse_stream], Package.build_from_path('yaml', package_name: 'psych', labels: %w[format.yaml provider.serialization])), 'JSON::Ext::Parser' => Hook.new(:parse, Package.build_from_path('json', package_name: 'json', labels: %w[format.json provider.serialization])), 'JSON::Ext::Generator::State' => Hook.new(:generate, Package.build_from_path('json', package_name: 'json', labels: %w[format.json provider.serialization])), }.freeze
Instance Attribute Summary collapse
-
#exclude ⇒ Object
readonly
Returns the value of attribute exclude.
-
#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
always_hook? indicates a method that should always be hooked.
- #find_hook(defined_class) ⇒ Object
- #find_package(defined_class, method_name) ⇒ Object
-
#included_by_location?(method) ⇒ Boolean
included_by_location? indicates a method whose source location matches a method definition that has been configured for inclusion.
-
#initialize(name, packages = [], exclude = []) ⇒ Config
constructor
A new instance of Config.
- #never_hook?(method) ⇒ Boolean
-
#package_for_method(method) ⇒ Object
package_for_method finds the Package, if any, which configures the hook for a method.
- #package_hooked_by_class(method) ⇒ Object
- #package_hooked_by_source_location(method) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name, packages = [], exclude = []) ⇒ Config
Returns a new instance of Config.
86 87 88 89 90 |
# File 'lib/appmap/config.rb', line 86 def initialize(name, packages = [], exclude = []) @name = name @packages = packages @exclude = exclude end |
Instance Attribute Details
#exclude ⇒ Object (readonly)
Returns the value of attribute exclude.
84 85 86 |
# File 'lib/appmap/config.rb', line 84 def exclude @exclude end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
84 85 86 |
# File 'lib/appmap/config.rb', line 84 def name @name end |
#packages ⇒ Object (readonly)
Returns the value of attribute packages.
84 85 86 |
# File 'lib/appmap/config.rb', line 84 def packages @packages end |
Class Method Details
.load(config_data) ⇒ Object
Loads configuration from a Hash.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/appmap/config.rb', line 100 def load(config_data) packages = (config_data['packages'] || []).map do |package| gem = package['gem'] path = package['path'] raise 'AppMap package configuration should specify gem or path, not both' if gem && path if gem shallow = package['shallow'] # shallow is true by default for gems shallow = true if shallow.nil? Package.build_from_gem(gem, exclude: package['exclude'] || [], shallow: shallow) else Package.build_from_path(path, exclude: package['exclude'] || [], shallow: package['shallow']) end end.compact Config.new config_data['name'], packages, config_data['exclude'] || [] end |
.load_from_file(config_file_name) ⇒ Object
Loads configuration data from a file, specified by the file name.
94 95 96 97 |
# File 'lib/appmap/config.rb', line 94 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
always_hook? indicates a method that should always be hooked.
156 157 158 |
# File 'lib/appmap/config.rb', line 156 def always_hook?(defined_class, method_name) !!find_package(defined_class, method_name) end |
#find_hook(defined_class) ⇒ Object
173 174 175 |
# File 'lib/appmap/config.rb', line 173 def find_hook(defined_class) HOOKED_METHODS[defined_class] || BUILTIN_METHODS[defined_class] end |
#find_package(defined_class, method_name) ⇒ Object
166 167 168 169 170 171 |
# File 'lib/appmap/config.rb', line 166 def find_package(defined_class, method_name) hook = find_hook(defined_class) return nil unless hook Array(hook.method_names).include?(method_name) ? hook.package : nil end |
#included_by_location?(method) ⇒ Boolean
included_by_location? indicates a method whose source location matches a method definition that has been configured for inclusion.
162 163 164 |
# File 'lib/appmap/config.rb', line 162 def included_by_location?(method) !!package_for_method(method) end |
#never_hook?(method) ⇒ Boolean
150 151 152 153 |
# File 'lib/appmap/config.rb', line 150 def never_hook?(method) defined_class, separator, method_name = ::AppMap::Hook.qualify_method_name(method) return true if exclude.member?(defined_class) || exclude.member?([ defined_class, separator, method_name ].join) end |
#package_for_method(method) ⇒ Object
package_for_method finds the Package, if any, which configures the hook for a method.
129 130 131 |
# File 'lib/appmap/config.rb', line 129 def package_for_method(method) package_hooked_by_class(method) || package_hooked_by_source_location(method) end |
#package_hooked_by_class(method) ⇒ Object
133 134 135 136 |
# File 'lib/appmap/config.rb', line 133 def package_hooked_by_class(method) defined_class, _, method_name = ::AppMap::Hook.qualify_method_name(method) return find_package(defined_class, method_name) end |
#package_hooked_by_source_location(method) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/appmap/config.rb', line 138 def package_hooked_by_source_location(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.select { |pkg| pkg.path }.find do |pkg| (location_file.index(pkg.path) == 0) && !pkg.exclude.find { |p| location_file.index(p) } end end |
#to_h ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/appmap/config.rb', line 119 def to_h { name: name, packages: packages.map(&:to_h), exclude: exclude } end |