Class: Banzai::IssuableExtractor
- Inherits:
-
Object
- Object
- Banzai::IssuableExtractor
- Defined in:
- lib/banzai/issuable_extractor.rb
Overview
This populates RequestStore cache used in Banzai::ReferenceParser::IssueParser and Banzai::ReferenceParser::MergeRequestParser Populating the cache should happen before processing documents one-by-one so we can avoid N+1 queries problem
Constant Summary collapse
- ISSUE_REFERENCE_TYPE =
'@data-reference-type="issue"'
- WORK_ITEM_REFERENCE_TYPE =
'@data-reference-type="work_item"'
- MERGE_REQUEST_REFERENCE_TYPE =
'@data-reference-type="merge_request"'
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
-
#extract(documents) ⇒ Object
Returns Hash in the form { node => issuable_instance }.
-
#initialize(context) ⇒ IssuableExtractor
constructor
context - An instance of Banzai::RenderContext.
Constructor Details
#initialize(context) ⇒ IssuableExtractor
context - An instance of Banzai::RenderContext.
19 20 21 |
# File 'lib/banzai/issuable_extractor.rb', line 19 def initialize(context) @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
12 13 14 |
# File 'lib/banzai/issuable_extractor.rb', line 12 def context @context end |
Instance Method Details
#extract(documents) ⇒ Object
Returns Hash in the form { node => issuable_instance }
24 25 26 27 28 29 30 31 32 |
# File 'lib/banzai/issuable_extractor.rb', line 24 def extract(documents) nodes = documents.flat_map do |document| document.xpath(query) end # The project or group for the issuable might be pending for deletion! # Filter them out because we don't care about them. issuables_for_nodes(nodes).select { |node, issuable| issuable.project || issuable.group } end |