Class: Decidim::FileZipper
- Inherits:
-
Object
- Object
- Decidim::FileZipper
- Defined in:
- lib/decidim/file_zipper.rb
Overview
This class performs a simple task: Zipping a single file. Originally meant for mailers to attach files, but other usage can be found.
Instance Method Summary collapse
-
#initialize(filename, data) ⇒ FileZipper
constructor
Public: Initializes the zipper with a filename and the data to be zipped.
-
#zip ⇒ Object
Public: Zips the file.
Constructor Details
#initialize(filename, data) ⇒ FileZipper
Public: Initializes the zipper with a filename and the data to be zipped.
filename - The file name of the file inside the zip. data - A string with the data to be zipped.
14 15 16 17 |
# File 'lib/decidim/file_zipper.rb', line 14 def initialize(filename, data) @data = data @filename = filename end |
Instance Method Details
#zip ⇒ Object
Public: Zips the file.
Returns a String with the zipped version of the file.
22 23 24 25 26 27 |
# File 'lib/decidim/file_zipper.rb', line 22 def zip @zip ||= Zip::OutputStream.write_buffer do |zipfile| zipfile.put_next_entry(@filename) zipfile.write @data end.string end |