Class: Mutant::Diff
- Inherits:
-
Object
- Object
- Mutant::Diff
- Includes:
- Adamantium::Flat
- Defined in:
- lib/mutant/diff.rb
Overview
Class to create diffs from source code
Constant Summary collapse
- ADDITION =
'+'.freeze
- DELETION =
'-'.freeze
- NEWLINE =
"\n".freeze
Class Method Summary collapse
-
.build(old, new) ⇒ Diff
private
Return new object.
Instance Method Summary collapse
-
#colorized_diff ⇒ String?
private
Return colorized source diff.
-
#diff ⇒ String?
private
Return source diff.
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.
Return new object
54 55 56 |
# File 'lib/mutant/diff.rb', line 54 def self.build(old, new) new(lines(old), lines(new)) end |
Instance Method Details
#colorized_diff ⇒ String?
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
37 38 39 40 41 42 |
# File 'lib/mutant/diff.rb', line 37 def colorized_diff return unless diff diff.lines.map do |line| self.class.colorize_line(line) end.join end |
#diff ⇒ String?
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
20 21 22 23 24 |
# File 'lib/mutant/diff.rb', line 20 def diff return unless diffs.length.equal?(1) ::Diff::LCS::Hunk.new(old, new, diffs.first, max_length, 0) .diff(:unified) << NEWLINE end |