Module: UsefulRenderers::ZipRenderable

Defined in:
lib/useful_renderers/zip_renderable.rb

Instance Method Summary collapse

Instance Method Details

#to_zipObject

You need to call this on collection of File objects or objects which provides :read & :path method



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/useful_renderers/zip_renderable.rb', line 10

def to_zip(*)
  return '' if empty?
  return '' unless first.respond_to?(:path) && first.respond_to?(:read)

  stringio = Zip::OutputStream.write_buffer do |zio|
    self.each do |obj|
      filename = File.basename(obj.path)
      zio.put_next_entry(filename)
      zio.write obj.read
    end
  end
  stringio.rewind
  stringio.sysread
end