Module: PrettyDiff

Defined in:
lib/pretty-diff.rb

Overview

This module is a namespace that holds everything

Defined Under Namespace

Classes: Diff

Class Method Summary collapse

Class Method Details

.files(one, two, options = {}) ⇒ Object

verify that files exist and then pass them off to PrettyFileDiff::Diff



15
16
17
18
19
20
21
# File 'lib/pretty-diff.rb', line 15

def self.files one, two, options = {}
  if File.file?(one) && File.file?(two)
    return Diff.new one, two, options
  else
    raise ArgumentError
  end
end

.strings(one, two, options = {}) ⇒ Object

makes temporary files from the strings so that the diff command can do its work, passes off to PrettyFileDiff::Diff, and then deletes the temproary files



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pretty-diff.rb', line 26

def self.strings one, two, options = {}
  require 'tempfile'

  file_one = Tempfile.new('fileone')
  file_two = Tempfile.new('filetwo')
  file_one.write(one)
  file_two.write(two)
  file_one.close
  file_two.close

  diff = Diff.new file_one.path, file_two.path, options

  file_one.unlink
  file_two.unlink

  return diff
end