Class: Codeowners::Checker::Group::Pattern
- Defined in:
- lib/codeowners/checker/group/pattern.rb
Overview
Defines and manages line type pattern. Parse the line into pattern, owners and whitespaces.
Instance Attribute Summary collapse
-
#owners ⇒ Object
Returns the value of attribute owners.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#spec ⇒ Object
readonly
Returns the value of attribute spec.
-
#whitespace ⇒ Object
Returns the value of attribute whitespace.
Attributes inherited from Line
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(line) ⇒ Pattern
constructor
A new instance of Pattern.
- #match_file?(file) ⇒ Boolean
- #owner ⇒ Object
-
#parse(line) ⇒ Object
Parse the line counting whitespaces between pattern and owners.
- #parse_spec(pattern) ⇒ Object
- #rename_owner(owner, new_owner) ⇒ Object
-
#to_file(preserve_whitespaces: true) ⇒ Object
Use @param preserve_whitespaces to keep the previous identation.
- #to_s ⇒ Object
Methods inherited from Line
#<=>, #==, build, #pattern?, #remove!, subclasses, #to_content, #to_tree
Constructor Details
#initialize(line) ⇒ Pattern
Returns a new instance of Pattern.
21 22 23 24 |
# File 'lib/codeowners/checker/group/pattern.rb', line 21 def initialize(line) super parse(line) end |
Instance Attribute Details
#owners ⇒ Object
Returns the value of attribute owners.
13 14 15 |
# File 'lib/codeowners/checker/group/pattern.rb', line 13 def owners @owners end |
#pattern ⇒ Object
Returns the value of attribute pattern.
14 15 16 |
# File 'lib/codeowners/checker/group/pattern.rb', line 14 def pattern @pattern end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
14 15 16 |
# File 'lib/codeowners/checker/group/pattern.rb', line 14 def spec @spec end |
#whitespace ⇒ Object
Returns the value of attribute whitespace.
13 14 15 |
# File 'lib/codeowners/checker/group/pattern.rb', line 13 def whitespace @whitespace end |
Class Method Details
Instance Method Details
#match_file?(file) ⇒ Boolean
42 43 44 |
# File 'lib/codeowners/checker/group/pattern.rb', line 42 def match_file?(file) spec.match file end |
#owner ⇒ Object
26 27 28 |
# File 'lib/codeowners/checker/group/pattern.rb', line 26 def owner owners.first end |
#parse(line) ⇒ Object
Parse the line counting whitespaces between pattern and owners.
36 37 38 39 40 |
# File 'lib/codeowners/checker/group/pattern.rb', line 36 def parse(line) @pattern, *@owners = line.split(/\s+/) @whitespace = line.split('@').first.count(' ') - 1 @spec = parse_spec(@pattern) end |
#parse_spec(pattern) ⇒ Object
67 68 69 |
# File 'lib/codeowners/checker/group/pattern.rb', line 67 def parse_spec(pattern) PathSpec.from_lines(pattern) end |
#rename_owner(owner, new_owner) ⇒ Object
30 31 32 33 |
# File 'lib/codeowners/checker/group/pattern.rb', line 30 def rename_owner(owner, new_owner) owners.delete(owner) owners << new_owner unless owners.include?(new_owner) end |
#to_file(preserve_whitespaces: true) ⇒ Object
Use @param preserve_whitespaces to keep the previous identation.
56 57 58 59 60 61 |
# File 'lib/codeowners/checker/group/pattern.rb', line 56 def to_file(preserve_whitespaces: true) line = pattern spaces = preserve_whitespaces ? whitespace : 0 line << ' ' * spaces [line, *owners].join(' ') end |
#to_s ⇒ Object
63 64 65 |
# File 'lib/codeowners/checker/group/pattern.rb', line 63 def to_s to_file(preserve_whitespaces: false) end |