Class: ZipWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/zip_dsl/zip_writer.rb

Instance Method Summary collapse

Constructor Details

#initialize(from_root, to_root, name) ⇒ ZipWriter

Returns a new instance of ZipWriter.



5
6
7
8
9
10
11
# File 'lib/zip_dsl/zip_writer.rb', line 5

def initialize from_root, to_root, name
  @from_root = from_root

  @zos = Zip::ZipOutputStream.new("#{to_root}/#{name}")

  @compression_level = Zlib::BEST_COMPRESSION
end

Instance Method Details

#closeObject



13
14
15
# File 'lib/zip_dsl/zip_writer.rb', line 13

def close
  @zos.close
end

#content(params) ⇒ Object



23
24
25
26
27
# File 'lib/zip_dsl/zip_writer.rb', line 23

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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/zip_dsl/zip_writer.rb', line 29

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



17
18
19
20
21
# File 'lib/zip_dsl/zip_writer.rb', line 17

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