Class: Reyes::Diff
- Inherits:
-
Object
- Object
- Reyes::Diff
- Defined in:
- lib/reyes/diff.rb
Instance Method Summary collapse
-
#diff ⇒ String?
Consumes the
Diff
, returning the full unified diff of @old and @new. -
#initialize ⇒ Diff
constructor
A new instance of Diff.
-
#new ⇒ File
Returns a handle to the underlying File for new, allowing the caller to populate it’s contents.
-
#old ⇒ File
Returns a handle to the underlying File for old, allowing the caller to populate it’s contents.
Constructor Details
#initialize ⇒ Diff
Returns a new instance of Diff.
3 4 5 6 |
# File 'lib/reyes/diff.rb', line 3 def initialize @old = Tempfile.new('diff.old.') @new = Tempfile.new('diff.new.') end |
Instance Method Details
#diff ⇒ String?
Consumes the Diff
, returning the full unified diff of @old and @new
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/reyes/diff.rb', line 10 def diff raise "Diff has already been created" unless @old && @new [@old, @new].each do |f| f.flush end output = nil cmd = ["diff", '-u', @old.path, @new.path] status = Subprocess.call(cmd, :stdout => Subprocess::PIPE) do |c| output, _ = c.communicate end case status.exitstatus when 0 # no diff return nil when 1 # files differ return output else # trouble raise Subprocess::NonZeroExit.new(cmd, status) end ensure @old.unlink @old = nil @new.unlink @new = nil end |
#new ⇒ File
Returns a handle to the underlying File for new, allowing the caller to populate it’s contents
51 52 53 |
# File 'lib/reyes/diff.rb', line 51 def new @new end |
#old ⇒ File
Returns a handle to the underlying File for old, allowing the caller to populate it’s contents
44 45 46 |
# File 'lib/reyes/diff.rb', line 44 def old @old end |