Class: Zip::FileSystem::ZipFsDir
- Inherits:
-
Object
- Object
- Zip::FileSystem::ZipFsDir
- Defined in:
- lib/zip/filesystem.rb
Overview
Instances of this class are normally accessed via the accessor ZipFile::dir. An instance of ZipFsDir behaves like ruby’s builtin Dir (class) object, except it works on ZipFile entries.
The individual methods are not documented due to their similarity with the methods in Dir
Instance Attribute Summary collapse
-
#file ⇒ Object
writeonly
Sets the attribute file.
Instance Method Summary collapse
- #chdir(directory_name) ⇒ Object
- #chroot(*_args) ⇒ Object
- #delete(entry_name) ⇒ Object (also: #rmdir, #unlink)
- #entries(directory_name) ⇒ Object
- #foreach(directory_name) ⇒ Object
- #glob(*args, &block) ⇒ Object
-
#initialize(mapped_zip) ⇒ ZipFsDir
constructor
A new instance of ZipFsDir.
- #mkdir(entry_name, permissions = 0o755) ⇒ Object
- #new(directory_name) ⇒ Object
- #open(directory_name) ⇒ Object
- #pwd ⇒ Object (also: #getwd)
Constructor Details
#initialize(mapped_zip) ⇒ ZipFsDir
Returns a new instance of ZipFsDir.
436 437 438 |
# File 'lib/zip/filesystem.rb', line 436 def initialize(mapped_zip) @mapped_zip = mapped_zip end |
Instance Attribute Details
#file=(value) ⇒ Object (writeonly)
Sets the attribute file
440 441 442 |
# File 'lib/zip/filesystem.rb', line 440 def file=(value) @file = value end |
Instance Method Details
#chdir(directory_name) ⇒ Object
464 465 466 467 468 469 470 |
# File 'lib/zip/filesystem.rb', line 464 def chdir(directory_name) unless @file.stat(directory_name).directory? raise Errno::EINVAL, "Invalid argument - #{directory_name}" end @mapped_zip.pwd = @file.(directory_name) end |
#chroot(*_args) ⇒ Object
511 512 513 |
# File 'lib/zip/filesystem.rb', line 511 def chroot(*_args) raise NotImplementedError, 'The chroot() function is not implemented' end |
#delete(entry_name) ⇒ Object Also known as: rmdir, unlink
497 498 499 500 501 502 503 |
# File 'lib/zip/filesystem.rb', line 497 def delete(entry_name) unless @file.stat(entry_name).directory? raise Errno::EINVAL, "Invalid argument - #{entry_name}" end @mapped_zip.remove(entry_name) end |
#entries(directory_name) ⇒ Object
472 473 474 475 476 |
# File 'lib/zip/filesystem.rb', line 472 def entries(directory_name) entries = [] foreach(directory_name) { |e| entries << e } entries end |
#foreach(directory_name) ⇒ Object
482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/zip/filesystem.rb', line 482 def foreach(directory_name) unless @file.stat(directory_name).directory? raise Errno::ENOTDIR, directory_name end path = @file.(directory_name) path << '/' unless path.end_with?('/') path = Regexp.escape(path) subdir_entry_regex = Regexp.new("^#{path}([^/]+)$") @mapped_zip.each do |filename| match = subdir_entry_regex.match(filename) yield(match[1]) unless match.nil? end end |
#glob(*args, &block) ⇒ Object
478 479 480 |
# File 'lib/zip/filesystem.rb', line 478 def glob(*args, &block) @mapped_zip.glob(*args, &block) end |
#mkdir(entry_name, permissions = 0o755) ⇒ Object
507 508 509 |
# File 'lib/zip/filesystem.rb', line 507 def mkdir(entry_name, = 0o755) @mapped_zip.mkdir(entry_name, ) end |
#new(directory_name) ⇒ Object
442 443 444 |
# File 'lib/zip/filesystem.rb', line 442 def new(directory_name) ZipFsDirIterator.new(entries(directory_name)) end |
#open(directory_name) ⇒ Object
446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/zip/filesystem.rb', line 446 def open(directory_name) dir_iter = new(directory_name) if block_given? begin yield(dir_iter) return nil ensure dir_iter.close end end dir_iter end |
#pwd ⇒ Object Also known as: getwd
459 460 461 |
# File 'lib/zip/filesystem.rb', line 459 def pwd @mapped_zip.pwd end |