Class: ZipDir::Zip
- Inherits:
-
Object
- Object
- ZipDir::Zip
- Defined in:
- lib/zip_dir/zip.rb
Instance Attribute Summary collapse
-
#source_path ⇒ Object
readonly
Returns the value of attribute source_path.
Instance Method Summary collapse
- #file ⇒ Object
- #generate ⇒ Object
- #generated? ⇒ Boolean
-
#initialize(source_path, filename = "zip.zip") ⇒ Zip
constructor
A new instance of Zip.
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_path ⇒ Object (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
#file ⇒ Object
9 10 11 12 |
# File 'lib/zip_dir/zip.rb', line 9 def file generate unless generated? @file end |
#generate ⇒ Object
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
21 22 23 |
# File 'lib/zip_dir/zip.rb', line 21 def generated? !!@generated end |