Class: ZipWriter
- Inherits:
-
Object
- Object
- ZipWriter
- Defined in:
- lib/zip_dsl/zip_writer.rb
Instance Attribute Summary collapse
-
#from_dir ⇒ Object
readonly
Returns the value of attribute from_dir.
Instance Method Summary collapse
- #close ⇒ Object
- #content(params) ⇒ Object
- #directory(params) ⇒ Object
- #file(params) ⇒ Object
-
#initialize(name, from_dir) ⇒ ZipWriter
constructor
A new instance of ZipWriter.
Constructor Details
#initialize(name, from_dir) ⇒ ZipWriter
Returns a new instance of ZipWriter.
6 7 8 9 10 11 12 |
# File 'lib/zip_dsl/zip_writer.rb', line 6 def initialize name, from_dir @from_dir = from_dir @zos = Zip::ZipOutputStream.new(name) @compression_level = Zlib::BEST_COMPRESSION end |
Instance Attribute Details
#from_dir ⇒ Object (readonly)
Returns the value of attribute from_dir.
4 5 6 |
# File 'lib/zip_dsl/zip_writer.rb', line 4 def from_dir @from_dir end |
Instance Method Details
#close ⇒ Object
14 15 16 |
# File 'lib/zip_dsl/zip_writer.rb', line 14 def close @zos.close end |
#content(params) ⇒ Object
24 25 26 27 28 |
# File 'lib/zip_dsl/zip_writer.rb', line 24 def content params to_dir = params[:to_dir].nil? ? File.dirname(params[:name]) : params[:to_dir] add params[:name], to_dir, params[:source] end |
#directory(params) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/zip_dsl/zip_writer.rb', line 30 def directory params if params[:from_dir].nil? add_empty_directory params[:to_dir] else if params[:to_dir].nil? to_dir = params[:from_dir] else to_dir = params[:to_dir] end filter = params[:filter].nil? ? "**/*" : params[:filter] add_directory params[:from_dir], to_dir, filter end end |
#file(params) ⇒ Object
18 19 20 21 22 |
# File 'lib/zip_dsl/zip_writer.rb', line 18 def file params to_dir = params[:to_dir].nil? ? File.dirname(params[:name]) : strip_dot(params[:to_dir]) add_file full_name(params[:name]), to_dir end |