class WinRM::FS::Core::RubyZipFactory
Creates a zip file using RubyZip
Attributes
basedir[R]
zip_definition[R]
Public Class Methods
new(zip_definition)
click to toggle source
# File lib/winrm-fs/core/temp_zip_file.rb, line 122 def initialize(zip_definition) @zip_definition = zip_definition @basedir = zip_definition.basedir @zip = Zip::File.open(zip_definition.path, Zip::File::CREATE) end
Public Instance Methods
build()
click to toggle source
# File lib/winrm-fs/core/temp_zip_file.rb, line 128 def build @zip_definition.paths.each do | path | absolute_path = File.expand_path(path, basedir) fail "#{path} doesn't exist" unless File.exist? absolute_path if File.directory?(absolute_path) add_directory(path) else add_file(path) end end close end
close()
click to toggle source
# File lib/winrm-fs/core/temp_zip_file.rb, line 142 def close @zip.close if @zip end
Private Instance Methods
add_directory(dir)
click to toggle source
Adds all files in the specified directory recursively into the zip file @param [String] Directory to add into zip
# File lib/winrm-fs/core/temp_zip_file.rb, line 150 def add_directory(dir) glob_pattern = '*' glob_pattern = '**/*' if zip_definition.options[:recurse_paths] glob = File.join(basedir, dir, glob_pattern) Dir.glob(glob).each do |file| add_file(file) end end
add_file(file)
click to toggle source
# File lib/winrm-fs/core/temp_zip_file.rb, line 160 def add_file(file) write_zip_entry(file, basedir) end
new_zip_entry(file_entry_path)
click to toggle source
# File lib/winrm-fs/core/temp_zip_file.rb, line 171 def new_zip_entry(file_entry_path) Zip::Entry.new( @zip, file_entry_path, nil, nil, nil, nil, nil, nil, ::Zip::DOSTime.new(2000)) end
write_zip_entry(file, _file_entry_path)
click to toggle source
# File lib/winrm-fs/core/temp_zip_file.rb, line 164 def write_zip_entry(file, _file_entry_path) absolute_file = File.expand_path(file, basedir) relative_file = Pathname.new(absolute_file).relative_path_from(basedir).to_s entry = new_zip_entry(relative_file) @zip.add(entry, absolute_file) end