Class: Mutant::Differ

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

Overview

Class to create diffs from source code

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(old, new) ⇒ Differ

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.

Return new object

Parameters:

  • old (String)
  • new (String)

Returns:



62
63
64
# File 'lib/mutant/differ.rb', line 62

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.

Return colorized source diff

Returns:

  • (String)

    if there is a diff

  • (nil)

    otherwise



45
46
47
48
49
50
# File 'lib/mutant/differ.rb', line 45

def colorized_diff
  return unless diff
  diff.lines.map do |line|
    self.class.colorize_line(line)
  end.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.

Return source diff

Returns:

  • (String)

    if there is a diff

  • (nil)

    otherwise



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mutant/differ.rb', line 18

def diff
  case diffs.length
  when 0
    nil
  when 1
    Diff::LCS::Hunk.new(old, new, diffs.first, max_length, 0)
      .diff(:unified) << "\n"
  else
    $stderr.puts(
      'Mutation resulted in more than one diff, should not happen! ' +
      'PLS report a bug!'
    )
    nil
  end
end