Class: ZipDir::Zip

Inherits:
Object
  • Object
show all
Defined in:
lib/zip_dir/zip.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_path, filename = "zip.zip") ⇒ Zip

Returns a new instance of Zip.



4
5
6
7
# File 'lib/zip_dir/zip.rb', line 4

def initialize(source_path, filename="zip.zip")
  filename = filename.chomp(".zip")
  @source_path, @file = source_path, Tempfile.new(["#{filename}-", ".zip"])
end

Instance Attribute Details

#source_pathObject (readonly)

Returns the value of attribute source_path.



3
4
5
# File 'lib/zip_dir/zip.rb', line 3

def source_path
  @source_path
end

Instance Method Details

#fileObject



9
10
11
12
# File 'lib/zip_dir/zip.rb', line 9

def file
  generate unless generated?
  @file
end

#generateObject



14
15
16
17
18
19
# File 'lib/zip_dir/zip.rb', line 14

def generate
  ::Zip::File.open(@file.path, ::Zip::File::CREATE) do |zip_io|
    zip_path(zip_io)
  end
  @generated = true
end

#generated?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/zip_dir/zip.rb', line 21

def generated?
  !!@generated
end