Class: Zold::Diff
- Inherits:
-
Object
- Object
- Zold::Diff
- Defined in:
- lib/zold/commands/diff.rb
Overview
DIFF pulling command
Instance Method Summary collapse
-
#initialize(wallet:, copies:, log: Log::Quiet.new) ⇒ Diff
constructor
A new instance of Diff.
- #run(_ = []) ⇒ Object
Constructor Details
Instance Method Details
#run(_ = []) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/zold/commands/diff.rb', line 40 def run(_ = []) raise 'There are no remote copies, try FETCH first' if @copies.all.empty? cps = @copies.all.sort_by { |c| c[:score] }.reverse patch = Patch.new patch.start(Wallet.new(cps[0][:path])) cps[1..-1].each do |c| patch.join(Wallet.new(c[:path])) end before = File.read(@wallet.path) after = '' Tempfile.open do |f| patch.save(f, overwrite: true) after = File.read(f) end diff = Diffy::Diff.new(before, after, context: 0).to_s(:color) @log.info(diff) diff end |