Class: Gitlab::StringPlaceholderReplacer

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/string_placeholder_replacer.rb

Class Method Summary collapse

Class Method Details

.replace_string_placeholders(string, placeholder_regex = nil, &block) ⇒ Object

This method accepts the following paras

  • string: the string to be analyzed

  • placeholder_regex: i.e. /%project_path|project_id|default_branch|commit_sha/

  • block: this block will be called with each placeholder found in the string using

the placeholder regex. If the result of the block is nil, the original placeholder will be returned.


12
13
14
15
16
# File 'lib/gitlab/string_placeholder_replacer.rb', line 12

def self.replace_string_placeholders(string, placeholder_regex = nil, &block)
  return string if string.blank? || placeholder_regex.blank? || !block_given?

  replace_placeholders(string, placeholder_regex, &block)
end