Module: Aikido::Zen::Helpers Private

Defined in:
lib/aikido/zen/helpers.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

Class Method Details

.normalize_path(path) ⇒ String?

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.

Normalizes a path by:

1. Collapsing consecutive forward slashes into a single forward slash.
2. Removing forward trailing slash, unless the normalized path is "/".

Parameters:

  • path (String, nil)

    the path to normalize.

Returns:

  • (String, nil)

    the normalized path.



14
15
16
17
18
19
20
21
# File 'lib/aikido/zen/helpers.rb', line 14

def self.normalize_path(path)
  return path unless path

  normalized_path = path.dup
  normalized_path.squeeze!("/")
  normalized_path.chomp!("/") unless normalized_path == "/"
  normalized_path
end

.regexp_with_timeout(regexp, timeout: Aikido::Zen.config.redos_regexp_timeout) ⇒ Regexp

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 a copy of the regexp with the timeout set if timeout is supported.

Parameters:

  • regexp (Regexp)

    the regexp

Returns:

  • (Regexp)

    the regexp with timeout set



27
28
29
30
31
# File 'lib/aikido/zen/helpers.rb', line 27

def self.regexp_with_timeout(regexp, timeout: Aikido::Zen.config.redos_regexp_timeout)
  return regexp if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")

  Regexp.new(regexp.source, regexp.options, timeout: timeout)
end