Class: AndFeathers::Tarball
- Inherits:
-
Object
- Object
- AndFeathers::Tarball
- Includes:
- ContainsDirectories, ContainsFiles, Enumerable
- Defined in:
- lib/and_feathers/tarball.rb,
lib/and_feathers/tarball/file.rb,
lib/and_feathers/tarball/directory.rb,
lib/and_feathers/tarball/contains_files.rb,
lib/and_feathers/tarball/contains_directories.rb
Overview
The base tarball representation
Defined Under Namespace
Modules: ContainsDirectories, ContainsFiles Classes: Directory, File
Constant Summary
Constants included from ContainsFiles
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#each {|child| ... } ⇒ Object
Iterates through each entity in the tarball, depth-first.
-
#initialize(path = '.') ⇒ Tarball
constructor
Creates a new
Tarball
. -
#to_io ⇒ StringIO
Returns this
Tarball
as a GZipped and tarredStringIO
.
Methods included from ContainsDirectories
Methods included from ContainsFiles
Constructor Details
#initialize(path = '.') ⇒ Tarball
Creates a new Tarball
27 28 29 30 |
# File 'lib/and_feathers/tarball.rb', line 27 def initialize(path = '.') @path = path @children = [] end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
20 21 22 |
# File 'lib/and_feathers/tarball.rb', line 20 def path @path end |
Instance Method Details
#each {|child| ... } ⇒ Object
Iterates through each entity in the tarball, depth-first
37 38 39 40 41 42 |
# File 'lib/and_feathers/tarball.rb', line 37 def each(&block) @children.each do |child| block.call(child) child.each(&block) end end |
#to_io ⇒ StringIO
Returns this Tarball
as a GZipped and tarred StringIO
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/and_feathers/tarball.rb', line 49 def to_io tarball_io = StringIO.new("") Gem::Package::TarWriter.new(tarball_io) do |tar| each do |child| case child when File tar.add_file(child.path, child.mode) do |file| file.write child.read end when Directory tar.mkdir(child.path, child.mode) end end end gzip_io = StringIO.new("") Zlib::GzipWriter.new(gzip_io).tap do |writer| writer.write(tarball_io.tap(&:rewind).string) writer.close end StringIO.new(gzip_io.string) end |