Sha256: 6a7232032b0eb079a33766724bc3d40ca3463bea75e585667e9eba7898418708

Contents?: true

Size: 596 Bytes

Versions: 8

Compression:

Stored size: 596 Bytes

Contents

require 'rubygems'
require 'zip'

module UsefulRenderers
  module ZipRenderable

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

    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
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
useful_renderers-0.3.0 lib/useful_renderers/zip_renderable.rb
useful_renderers-0.2.0 lib/useful_renderers/zip_renderable.rb
useful_renderers-0.1.0 lib/useful_renderers/zip_renderable.rb
useful_renderers-0.0.5 lib/useful_renderers/zip_renderable.rb
useful_renderers-0.0.4 lib/useful_renderers/zip_renderable.rb
useful_renderers-0.0.3 lib/useful_renderers/zip_renderable.rb
useful_renderers-0.0.2 lib/useful_renderers/zip_renderable.rb
useful_renderers-0.0.1 lib/useful_renderers/zip_renderable.rb