Module: Mentionable::ReferenceRegexes

Extended by:
Gitlab::Utils::StrongMemoize
Defined in:
app/models/concerns/mentionable/reference_regexes.rb

Class Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

clear_memoization, strong_memoize, strong_memoized?

Class Method Details

.default_patternObject


22
23
24
25
26
27
28
# File 'app/models/concerns/mentionable/reference_regexes.rb', line 22

def self.default_pattern
  strong_memoize(:default_pattern) do
    issue_pattern = Issue.reference_pattern
    link_patterns = Regexp.union([Issue, Commit, MergeRequest, Epic].map(&:link_reference_pattern).compact)
    reference_pattern(link_patterns, issue_pattern)
  end
end

.external_patternObject


30
31
32
33
34
35
36
# File 'app/models/concerns/mentionable/reference_regexes.rb', line 30

def self.external_pattern
  strong_memoize(:external_pattern) do
    issue_pattern = IssueTrackerService.reference_pattern
    link_patterns = URI::DEFAULT_PARSER.make_regexp(%w(http https))
    reference_pattern(link_patterns, issue_pattern)
  end
end

.other_patternsObject


13
14
15
16
17
18
19
20
# File 'app/models/concerns/mentionable/reference_regexes.rb', line 13

def self.other_patterns
  [
    Commit.reference_pattern,
    MergeRequest.reference_pattern,
    Label.reference_pattern,
    Milestone.reference_pattern
  ]
end

.reference_pattern(link_patterns, issue_pattern) ⇒ Object


7
8
9
10
11
# File 'app/models/concerns/mentionable/reference_regexes.rb', line 7

def self.reference_pattern(link_patterns, issue_pattern)
  Regexp.union(link_patterns,
               issue_pattern,
               *other_patterns)
end