Class: Ledmon::Monster::Packer
- Inherits:
-
Object
- Object
- Ledmon::Monster::Packer
- Defined in:
- lib/ledmon/monster/packer.rb
Defined Under Namespace
Classes: FileTooLargeError, PackTooLargeError
Constant Summary collapse
- MAX_FILE_SIZE =
100.kilobytes
- MAX_PACK_SIZE =
10.megabytes
Instance Method Summary collapse
-
#initialize(path:) ⇒ Packer
constructor
A new instance of Packer.
- #pack! ⇒ Object
Constructor Details
#initialize(path:) ⇒ Packer
Returns a new instance of Packer.
16 17 18 19 |
# File 'lib/ledmon/monster/packer.rb', line 16 def initialize(path:) @path = path @current_pack_size = 0 end |
Instance Method Details
#pack! ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ledmon/monster/packer.rb', line 21 def pack! raise ArgumentError, "Block required" unless block_given? Tempfile.create(%w[ledmon_pack .tar.gz]) do |tempfile| tempfile.binmode Zlib::GzipWriter.wrap(tempfile) do |gz| Gem::Package::TarWriter.new(gz) do |tar| pack_directory(tar, @path) end end yield tempfile.path end end |