Class: CommunityTheatre::SplicingSpooler
- Inherits:
-
DisposableSpooler
- Object
- DisposableSpooler
- CommunityTheatre::SplicingSpooler
- Defined in:
- lib/community_theatre/splicing_spooler.rb
Instance Method Summary collapse
-
#initialize(dest, page_size: 100) ⇒ SplicingSpooler
constructor
A new instance of SplicingSpooler.
- #spool!(enumerable) ⇒ Object
Methods inherited from DisposableSpooler
Constructor Details
#initialize(dest, page_size: 100) ⇒ SplicingSpooler
Returns a new instance of SplicingSpooler.
7 8 9 |
# File 'lib/community_theatre/splicing_spooler.rb', line 7 def initialize(dest, page_size: 100) super(dest, page_size: page_size) end |
Instance Method Details
#spool!(enumerable) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/community_theatre/splicing_spooler.rb', line 11 def spool!(enumerable) pages = existing_pages # for convenience's sake, rebuild the last page now starting_page = [pages.size - 1, 0].max skip_number = starting_page * @page_size enumerable.seek_to!(skip_number, last_entry_of_second_last_page) enumerable.each_slice(@page_size).each_with_index do |page, index| file_for_page(index + starting_page) do |file| packer = MessagePack::Packer.new(file) packer.write_array_header(page.size) page.each { |item| packer.write(item) } packer.flush end end end |