class WinRM::FS::Core::TempZipFile

Temporary zip file on the local system

Attributes

basedir[R]
options[R]
path[R]
paths[R]
zip_file[R]

Public Class Methods

new(basedir = Dir.pwd, options = {}) click to toggle source

Creates a new local temporary zip file @param [String] Base directory to use when expanding out files passed to add @param [Hash] Options: #zip_file, via, recurse_paths

# File lib/winrm-fs/core/temp_zip_file.rb, line 31
def initialize(basedir = Dir.pwd, options = {})
  @basedir = Pathname.new(basedir)
  @options = options
  @zip_file = options[:zip_file] || Tempfile.new(['winrm_upload', '.zip'])
  @zip_file.close unless @zip_file.respond_to?('closed?') && @zip_file.closed?
  @path = Pathname.new(@zip_file)
end

Public Instance Methods

add(*new_paths) click to toggle source

Adds a file or directory to the temporary zip file @param [String] Directory or file path relative to basedir to add into zip

# File lib/winrm-fs/core/temp_zip_file.rb, line 41
def add(*new_paths)
  new_paths.each do | path |
    absolute_path = File.expand_path(path, basedir)
    fail "#{path} must exist relative to #{basedir}" unless File.exist? absolute_path
    paths << Pathname.new(absolute_path).relative_path_from(basedir)
  end
end
build() click to toggle source
# File lib/winrm-fs/core/temp_zip_file.rb, line 57
def build
  factory.new(self).build
end
delete() click to toggle source
# File lib/winrm-fs/core/temp_zip_file.rb, line 53
def delete
  @zip_file.delete
end

Private Instance Methods

factory() click to toggle source
# File lib/winrm-fs/core/temp_zip_file.rb, line 63
def factory
  @factory ||= case options[:via]
               when nil, :rubyzip
                 RubyZipFactory
               when :shell
                 ShellZipFactory
               else
                 fail "Unknown zip factory: #{factory}"
               end
end