Class: DevSystem::LineDiffShell

Inherits:
Shell show all
Defined in:
lib/dev_system/sub/shell/shells/line_diff_shell.rb

Class Method Summary collapse

Methods inherited from Shell

cruby?, engine, jruby?, linux?, mac?, os, ruby_version, unix?, windows?

Methods inherited from Liza::Controller

color, inherited, on_connected

Methods inherited from Liza::Unit

const_missing, division, part, system, #system, test_class

Class Method Details

.log_diff(a, b) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dev_system/sub/shell/shells/line_diff_shell.rb', line 5

def self.log_diff(a, b)
  require "diff/lcs"

  # Compute the diff
  diffs = Diff::LCS.diff(a, b)
  puts
  # Output the diff in a format similar to git diff
  diffs.each do |diff|
    diff.each do |change|
      # If it's a deletion (present in old but not in new)
      if change.action == "-"
        puts "- #{change.element.chomp.red}"
      # If it's an addition (present in new but not in old)
      elsif change.action == "+"
        puts "+ #{change.element.chomp.green}"
      end
    end
  end
  puts
end