Sha256: 534cca98e788a1ba480b05e14d3399754ba9e988127f939395439a23586b14e6
Contents?: true
Size: 1.54 KB
Versions: 4
Compression:
Stored size: 1.54 KB
Contents
# frozen_string_literal: true module Datadog module DI module Utils # 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. module_function def path_matches_suffix?(path, suffix) 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 end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
datadog-2.7.1 | lib/datadog/di/utils.rb |
datadog-2.7.0 | lib/datadog/di/utils.rb |
datadog-2.6.0 | lib/datadog/di/utils.rb |
datadog-2.5.0 | lib/datadog/di/utils.rb |