Module: Datadog::DI::Utils Private
- Defined in:
- lib/datadog/di/utils.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Class Method Summary collapse
-
.path_can_match_spec?(path, spec) ⇒ Boolean
private
Returns whether the provided
path
matches the “probe path” inspec
. -
.path_matches_suffix?(path, suffix) ⇒ Boolean
private
Returns whether the provided
path
matches the user-designated file suffix (of a line probe).
Class Method Details
.path_can_match_spec?(path, spec) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether the provided path
matches the “probe path” in spec
. Attempts all of the fuzzy matches by stripping directories from the front of spec
. Does not consider othr known paths to identify the case of (potentially) multiple matching paths for spec
.
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/datadog/di/utils.rb', line 128 module_function def path_can_match_spec?(path, spec) return true if path_matches_suffix?(path, spec) spec = spec.dup loop do return false unless spec.include?('/') spec.sub!(%r{.*/+}, '') return true if path_matches_suffix?(path, spec) end end |
.path_matches_suffix?(path, suffix) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether the provided path
matches the user-designated file suffix (of a line probe).
If suffix is an absolute path (i.e., it starts with a slash), the path must be identical for it to match.
If suffix is not an absolute path, the path matches if its suffix is the provided suffix, at a path component boundary.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/datadog/di/utils.rb', line 93 module_function def path_matches_suffix?(path, suffix) if path.nil? raise ArgumentError, "nil path passed" end if suffix.nil? raise ArgumentError, "nil suffix passed" end if suffix.start_with?('/') path == suffix else # Exact match is not possible here, meaning any matching path # has to be longer than the suffix. Require full component matches, # meaning either the first character of the suffix is a slash # or the previous character in the path is a slash. # For now only check for forward slashes for Unix-like OSes; # backslash is a legitimate character of a file name in Unix # therefore simply permitting forward or back slash is not # sufficient, we need to perform an OS check to know which # path separator to use. !! if path.length > suffix.length && path.end_with?(suffix) previous_char = path[path.length - suffix.length - 1] previous_char == "/" || suffix[0] == "/" end # Alternative implementation using a regular expression: # !!(path =~ %r,(/|\A)#{Regexp.quote(suffix)}\z,) end end |