Class: Unparser::CLI::Differ
- Inherits:
-
Object
- Object
- Unparser::CLI::Differ
- Includes:
- Adamantium::Flat
- Defined in:
- lib/unparser/cli/differ.rb
Overview
Class to create diffs from source code
Constant Summary collapse
- CONTEXT_LINES =
5
Class Method Summary collapse
-
.build(old, new) ⇒ Differ
private
Return new object.
Instance Method Summary collapse
-
#collapsed_hunks ⇒ Enumerable<Diff::LCS::Hunk>
private
Return collapsed hunks.
-
#colorized_diff ⇒ String?
private
Return colorized source diff.
-
#diff ⇒ String?
private
Return source diff.
-
#hunks ⇒ Array<Diff::LCS::Hunk>
private
Return hunks.
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
91 92 93 |
# File 'lib/unparser/cli/differ.rb', line 91 def self.build(old, new) new(lines(old), lines(new)) end |
Instance Method Details
#collapsed_hunks ⇒ Enumerable<Diff::LCS::Hunk>
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 collapsed hunks
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/unparser/cli/differ.rb', line 32 def collapsed_hunks hunks.each_with_object([]) do |hunk, output| last = output.last if last && hunk.merge(last) output.pop end output << hunk end end |
#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
75 76 77 78 79 |
# File 'lib/unparser/cli/differ.rb', line 75 def colorized_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
54 55 56 57 58 59 60 61 62 |
# File 'lib/unparser/cli/differ.rb', line 54 def diff output = '' collapsed_hunks.each do |hunk| output << hunk.diff(:unified) << "\n" end output end |
#hunks ⇒ Array<Diff::LCS::Hunk>
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 hunks
17 18 19 20 21 22 23 24 |
# File 'lib/unparser/cli/differ.rb', line 17 def hunks file_length_difference = new.length - old.length diffs.map do |piece| hunk = Diff::LCS::Hunk.new(old, new, piece, CONTEXT_LINES, file_length_difference) file_length_difference = hunk.file_length_difference hunk end end |