Class: WinRM::FS::Core::TempZipFile

Inherits:
Object
  • Object
show all
Defined in:
lib/winrm-fs/core/temp_zip_file.rb

Overview

Temporary zip file on the local system

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(basedir = Dir.pwd, options = {}) ⇒ TempZipFile

Creates a new local temporary zip file

Parameters:

  • Base (String)

    directory to use when expanding out files passed to add

  • Options: (Hash)

    zip_file, via, recurse_paths



32
33
34
35
36
37
# File 'lib/winrm-fs/core/temp_zip_file.rb', line 32

def initialize(basedir = Dir.pwd, options = {})
  @basedir = Pathname.new(basedir)
  @options = options
  @zip_file = options[:zip_file] || Tempfile.new(['winrm_upload', '.zip'])
  @path = Pathname.new(@zip_file)
end

Instance Attribute Details

#basedirObject (readonly)

Returns the value of attribute basedir.



27
28
29
# File 'lib/winrm-fs/core/temp_zip_file.rb', line 27

def basedir
  @basedir
end

#optionsObject (readonly)

Returns the value of attribute options.



27
28
29
# File 'lib/winrm-fs/core/temp_zip_file.rb', line 27

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



27
28
29
# File 'lib/winrm-fs/core/temp_zip_file.rb', line 27

def path
  @path
end

#pathsObject (readonly)

Returns the value of attribute paths.



27
28
29
# File 'lib/winrm-fs/core/temp_zip_file.rb', line 27

def paths
  @paths
end

#zip_fileObject (readonly)

Returns the value of attribute zip_file.



27
28
29
# File 'lib/winrm-fs/core/temp_zip_file.rb', line 27

def zip_file
  @zip_file
end

Instance Method Details

#add(*new_paths) ⇒ Object

Adds a file or directory to the temporary zip file

Parameters:

  • Directory (String)

    or file path relative to basedir to add into zip



41
42
43
44
45
46
47
# 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

#buildObject



57
58
59
# File 'lib/winrm-fs/core/temp_zip_file.rb', line 57

def build
  factory.new(self).build
end

#deleteObject



53
54
55
# File 'lib/winrm-fs/core/temp_zip_file.rb', line 53

def delete
  @zip_file.delete
end