Class: Moult::Diff::ChangedFile

Inherits:
Struct
  • Object
show all
Defined in:
lib/moult/diff.rb

Overview

One changed file. status is git's single-letter code (A/M/D/R/C/...); line_ranges are the new-side changed line ranges (empty for a deletion, a pure-deletion hunk, or a content-less rename).

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#line_rangesObject

Returns the value of attribute line_ranges

Returns:

  • (Object)

    the current value of line_ranges



24
25
26
# File 'lib/moult/diff.rb', line 24

def line_ranges
  @line_ranges
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



24
25
26
# File 'lib/moult/diff.rb', line 24

def path
  @path
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



24
25
26
# File 'lib/moult/diff.rb', line 24

def status
  @status
end

Instance Method Details

#changed_line?(line) ⇒ Boolean

Does line fall on a changed/added line of this file?

Returns:

  • (Boolean)


26
27
28
# File 'lib/moult/diff.rb', line 26

def changed_line?(line)
  line_ranges.any? { |r| r.cover?(line) }
end

#changed_range?(lo, hi) ⇒ Boolean

Does the inclusive line range [lo, hi] intersect any changed range?

Returns:

  • (Boolean)


31
32
33
# File 'lib/moult/diff.rb', line 31

def changed_range?(lo, hi)
  line_ranges.any? { |r| r.begin <= hi && r.end >= lo }
end