Class: QuietQuality::ChangedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/quiet_quality/changed_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (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

Returns:

  • (Boolean)


17
18
19
# File 'lib/quiet_quality/changed_file.rb', line 17

def entire?
  @entire
end

#line_numbersObject



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

#linesObject



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