Class: Codeowners::Checker::LineGrouper
- Inherits:
-
Object
- Object
- Codeowners::Checker::LineGrouper
- Defined in:
- lib/codeowners/checker/line_grouper.rb
Overview
Create groups and subgroups structure for the lines in the CODEOWNERS file.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(group, lines) ⇒ LineGrouper
constructor
A new instance of LineGrouper.
Constructor Details
#initialize(group, lines) ⇒ LineGrouper
Returns a new instance of LineGrouper.
11 12 13 14 |
# File 'lib/codeowners/checker/line_grouper.rb', line 11 def initialize(group, lines) @group_buffer = [group] @lines = lines end |
Class Method Details
.call(group, lines) ⇒ Object
7 8 9 |
# File 'lib/codeowners/checker/line_grouper.rb', line 7 def self.call(group, lines) new(group, lines).call end |
Instance Method Details
#call ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/codeowners/checker/line_grouper.rb', line 16 def call lines.each_with_index do |line, index| case line when Codeowners::Checker::Group::Empty ensure_groups_structure when Codeowners::Checker::Group::GroupBeginComment trim_groups(line.level) create_groups_structure(line.level) when Codeowners::Checker::Group::GroupEndComment trim_subgroups(line.level) create_groups_structure(line.level) when Codeowners::Checker::Group::Comment if previous_line_empty?(index) trim_groups(line.level) else trim_subgroups(line.level) end create_groups_structure(line.level) when Codeowners::Checker::Group::Pattern if new_owner?(line, index) trim_groups(current_level) new_group end ensure_groups_structure when Codeowners::Checker::Group::UnrecognizedLine ensure_groups_structure else raise StandardError, "Do not know how to handle line: #{line.inspect}" end current_group.add(line) end group_buffer.first end |