Class: Mutant::Diff Private

Inherits:
Object
  • Object
show all
Includes:
Adamantium::Flat
Defined in:
lib/mutant/diff.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class to create diffs from source code

Constant Summary collapse

ADDITION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'+'
DELETION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'-'
NEWLINE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"\n"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(old, new) ⇒ Diff

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build new object from source strings

Parameters:

  • old (String)
  • new (String)

Returns:



45
46
47
# File 'lib/mutant/diff.rb', line 45

def self.build(old, new)
  new(lines(old), lines(new))
end

Instance Method Details

#colorized_diffString?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Colorized unified source diff between old and new

Returns:

  • (String)

    if there is a diff

  • (nil)

    otherwise



33
34
35
36
# File 'lib/mutant/diff.rb', line 33

def colorized_diff
  return unless diff
  diff.lines.map(&self.class.method(:colorize_line)).join
end

#diffString?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Unified source diff between old and new

Returns:

  • (String)

    if there is exactly one diff

  • (nil)

    otherwise



19
20
21
22
23
# File 'lib/mutant/diff.rb', line 19

def diff
  return if diffs.empty?

  minimized_hunk.diff(:unified) + NEWLINE
end