class GemMirror::MirrorFile
Similar to {GemMirror::MirrorDirectory} the MirrorFile
class is used to make it easier to read and write data in a directory that mirrors data from an external source.
@!attribute [r] path
@return [String]
Attributes
path[R]
Public Class Methods
new(path)
click to toggle source
@param [String] path
# File lib/gem_mirror/mirror_file.rb 18 def initialize(path) 19 @path = path 20 end
Public Instance Methods
read()
click to toggle source
Reads the content of the current file.
@return [String]
# File lib/gem_mirror/mirror_file.rb 40 def read 41 handle = File.open(path, "r") 42 content = handle.read 43 44 handle.close 45 46 content 47 end
read_gzip()
click to toggle source
Reads the contents of a Gzip encoded file.
@return [String]
# File lib/gem_mirror/mirror_file.rb 54 def read_gzip 55 content = nil 56 57 Zlib::GzipReader.open(path) do |gz| 58 content = gz.read 59 gz.close 60 end 61 62 content 63 end
write(content)
click to toggle source
Writes the specified content to the current file. Existing files are overwritten.
@param [String] content
# File lib/gem_mirror/mirror_file.rb 28 def write(content) 29 handle = File.open(path, "w") 30 31 handle.write(content) 32 handle.close 33 end