Class: QuietQuality::ChangedFile
- Inherits:
-
Object
- Object
- QuietQuality::ChangedFile
- Defined in:
- lib/quiet_quality/changed_file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #entire? ⇒ Boolean
-
#initialize(path:, lines:) ⇒ ChangedFile
constructor
A new instance of ChangedFile.
- #line_numbers ⇒ Object
- #lines ⇒ Object
- #merge(other) ⇒ Object
Constructor Details
#initialize(path:, lines:) ⇒ ChangedFile
Returns a new instance of ChangedFile.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/quiet_quality/changed_file.rb', line 5 def initialize(path:, lines:) @path = path if lines == :all || lines == "all" @entire = true @lines = nil else @entire = false @lines = lines end end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/quiet_quality/changed_file.rb', line 3 def path @path end |
Instance Method Details
#entire? ⇒ Boolean
17 18 19 |
# File 'lib/quiet_quality/changed_file.rb', line 17 def entire? @entire end |
#line_numbers ⇒ Object
26 27 28 29 |
# File 'lib/quiet_quality/changed_file.rb', line 26 def line_numbers return nil if @lines.nil? @_line_numbers ||= @lines.sort end |
#lines ⇒ Object
21 22 23 24 |
# File 'lib/quiet_quality/changed_file.rb', line 21 def lines return nil if @lines.nil? @_lines ||= @lines.to_set end |
#merge(other) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/quiet_quality/changed_file.rb', line 31 def merge(other) if path != other.path fail ArgumentError, "Cannot merge ChangedFiles '#{path}' and '#{other.path}', they're different files" end new_lines = (entire? || other.entire?) ? :all : (lines + other.lines).to_a self.class.new(path: path, lines: new_lines) end |