Class: Banzai::ReferenceParser::CommitRangeParser

Inherits:
BaseParser
  • Object
show all
Defined in:
lib/banzai/reference_parser/commit_range_parser.rb

Instance Method Summary collapse

Methods inherited from BaseParser

#can?, #collection_cache_key, #collection_objects_for_ids, data_attribute, #find_projects_for_hash_keys, #gather_attributes_per_project, #gather_references, #grouped_objects_for_nodes, #initialize, #nodes_user_can_reference, #nodes_visible_to_user, #process, #project_for_node, #projects_for_nodes, #references_relation, #unique_attribute_values

Constructor Details

This class inherits a constructor from Banzai::ReferenceParser::BaseParser

Instance Method Details

#commit_range_ids_per_project(nodes) ⇒ Object


17
18
19
# File 'lib/banzai/reference_parser/commit_range_parser.rb', line 17

def commit_range_ids_per_project(nodes)
  gather_attributes_per_project(nodes, self.class.data_attribute)
end

#find_object(project, id) ⇒ Object


33
34
35
36
37
38
39
# File 'lib/banzai/reference_parser/commit_range_parser.rb', line 33

def find_object(project, id)
  return unless project.is_a?(Project)

  range = CommitRange.new(id, project)

  range.valid_commits? ? range : nil
end

#find_ranges(project, range_ids) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/banzai/reference_parser/commit_range_parser.rb', line 21

def find_ranges(project, range_ids)
  ranges = []

  range_ids.each do |id|
    range = find_object(project, id)

    ranges << range if range
  end

  ranges
end

#referenced_by(nodes) ⇒ Object


8
9
10
11
12
13
14
15
# File 'lib/banzai/reference_parser/commit_range_parser.rb', line 8

def referenced_by(nodes)
  range_ids = commit_range_ids_per_project(nodes)
  projects = find_projects_for_hash_keys(range_ids)

  projects.flat_map do |project|
    find_ranges(project, range_ids[project.id])
  end
end