Class: Gitlab::ReferenceExtractor

Inherits:
Banzai::ReferenceExtractor show all
Defined in:
lib/gitlab/reference_extractor.rb

Overview

Extract possible GFM references from an arbitrary String for further processing.

Constant Summary collapse

REFERABLES =
user issue label milestone merge_request snippet commit commit_range

Constants inherited from Banzai::ReferenceExtractor

Banzai::ReferenceExtractor::LAZY_KEY

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Banzai::ReferenceExtractor

lazily, lazy?, #references

Constructor Details

#initialize(project, current_user = nil, author = nil) ⇒ ReferenceExtractor

Returns a new instance of ReferenceExtractor


7
8
9
10
11
12
13
14
15
# File 'lib/gitlab/reference_extractor.rb', line 7

def initialize(project, current_user = nil, author = nil)
  @project = project
  @current_user = current_user
  @author = author

  @references = {}

  super()
end

Instance Attribute Details

#authorObject

Returns the value of attribute author


5
6
7
# File 'lib/gitlab/reference_extractor.rb', line 5

def author
  @author
end

#current_userObject

Returns the value of attribute current_user


5
6
7
# File 'lib/gitlab/reference_extractor.rb', line 5

def current_user
  @current_user
end

#projectObject

Returns the value of attribute project


5
6
7
# File 'lib/gitlab/reference_extractor.rb', line 5

def project
  @project
end

Class Method Details

.references_patternObject


40
41
42
43
44
45
46
47
48
# File 'lib/gitlab/reference_extractor.rb', line 40

def self.references_pattern
  return @pattern if @pattern

  patterns = REFERABLES.map do |ref|
    ref.to_s.classify.constantize.try(:reference_pattern)
  end

  @pattern = Regexp.union(patterns.compact)
end

Instance Method Details

#allObject


35
36
37
38
# File 'lib/gitlab/reference_extractor.rb', line 35

def all
  REFERABLES.each { |referable| send(referable.to_s.pluralize) }
  @references.values.flatten
end

#analyze(text, context = {}) ⇒ Object


17
18
19
# File 'lib/gitlab/reference_extractor.rb', line 17

def analyze(text, context = {})
  super(text, context.merge(project: project))
end

#issuesObject


27
28
29
30
31
32
33
# File 'lib/gitlab/reference_extractor.rb', line 27

def issues
  if project && project.jira_tracker?
    @references[:external_issue] ||= references(:external_issue, reference_context)
  else
    @references[:issue] ||= references(:issue, reference_context)
  end
end