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, includes = [], excludes = []) ⇒ ZipWriter
constructor
A new instance of ZipWriter.
Constructor Details
#initialize(name, from_dir, includes = [], excludes = []) ⇒ ZipWriter
Returns a new instance of ZipWriter.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/zip_dsl/zip_writer.rb', line 7 def initialize name, from_dir, includes=[], excludes=[] @from_dir = from_dir @global_includes = includes @global_excludes = excludes if File.exist?(name) @zipfile = Zip::ZipFile.open(name) @new_file = false else @compression_level = Zlib::BEST_COMPRESSION @zos = Zip::ZipOutputStream.new(name) @new_file = true end end |
Instance Attribute Details
#from_dir ⇒ Object (readonly)
Returns the value of attribute from_dir.
5 6 7 |
# File 'lib/zip_dsl/zip_writer.rb', line 5 def from_dir @from_dir end |
Instance Method Details
#close ⇒ Object
22 23 24 |
# File 'lib/zip_dsl/zip_writer.rb', line 22 def close @new_file ? @zos.close : @zipfile.close end |
#content(params) ⇒ Object
36 37 38 39 40 |
# File 'lib/zip_dsl/zip_writer.rb', line 36 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
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/zip_dsl/zip_writer.rb', line 42 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 includes = build_filter(params[:includes], @global_includes) excludes = build_filter(params[:excludes], @global_excludes) add_directory File.(params[:from_dir]), to_dir, includes, excludes end end |
#file(params) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/zip_dsl/zip_writer.rb', line 26 def file params to_dir = params[:to_dir].nil? ? File.dirname(params[:name]) : strip_dot(params[:to_dir]) if @new_file add_file full_name(params[:name]), to_dir else add_or_replace_file full_name(params[:name]), "#{to_dir}/#{params[:name]}" end end |