Class: Darcs::PatchWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/darcs/patchwriter.rb

Overview

A PatchWriter is used to write PatchChunks into a patch.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(patch) ⇒ PatchWriter

Create a new PatchWriter for writing the patch file associated with the given patch object



11
12
13
14
15
16
# File 'lib/darcs/patchwriter.rb', line 11

def initialize(patch)
  @patch = patch
  @file = File.open(patch.filename, 'w')
  @gz = Zlib::GzipWriter.new(@file)
  @gz.write(patch.info.to_s + " {\n")
end

Instance Attribute Details

#patchObject (readonly)

Returns the value of attribute patch.



18
19
20
# File 'lib/darcs/patchwriter.rb', line 18

def patch
  @patch
end

Instance Method Details

#<<(chunk) ⇒ Object

Writes a patch chunk to the file



39
40
41
# File 'lib/darcs/patchwriter.rb', line 39

def << (chunk)
  chunk.write(@gz, patch)
end

#abortObject

Closes files and deletes the patch file



27
28
29
30
31
32
33
34
35
36
# File 'lib/darcs/patchwriter.rb', line 27

def abort
  begin
    @gz.close
  rescue
  end
  begin
    File.delete(patch.filename)
  rescue
  end
end

#finishObject

Finishes writing the patch and close files



21
22
23
24
# File 'lib/darcs/patchwriter.rb', line 21

def finish
  @gz.write("}\n")
  @gz.close
end