Class: Zip::FileSystem::Dir

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

Overview

:nodoc:all

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mapped_zip) ⇒ Dir

Returns a new instance of Dir.



6
7
8
# File 'lib/zip/filesystem/dir.rb', line 6

def initialize(mapped_zip)
  @mapped_zip = mapped_zip
end

Instance Attribute Details

#file=(value) ⇒ Object (writeonly)

Sets the attribute file

Parameters:

  • value

    the value to set the attribute file to.



10
11
12
# File 'lib/zip/filesystem/dir.rb', line 10

def file=(value)
  @file = value
end

Instance Method Details

#chdir(directory_name) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/zip/filesystem/dir.rb', line 34

def chdir(directory_name)
  unless @file.stat(directory_name).directory?
    raise Errno::EINVAL, "Invalid argument - #{directory_name}"
  end

  @mapped_zip.pwd = @file.expand_path(directory_name)
end

#chroot(*_args) ⇒ Object

Raises:

  • (NotImplementedError)


81
82
83
# File 'lib/zip/filesystem/dir.rb', line 81

def chroot(*_args)
  raise NotImplementedError, 'The chroot() function is not implemented'
end

#delete(entry_name) ⇒ Object Also known as: rmdir, unlink



67
68
69
70
71
72
73
# File 'lib/zip/filesystem/dir.rb', line 67

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



42
43
44
45
46
# File 'lib/zip/filesystem/dir.rb', line 42

def entries(directory_name)
  entries = []
  foreach(directory_name) { |e| entries << e }
  entries
end

#foreach(directory_name) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/zip/filesystem/dir.rb', line 52

def foreach(directory_name)
  unless @file.stat(directory_name).directory?
    raise Errno::ENOTDIR, directory_name
  end

  path = @file.expand_path(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



48
49
50
# File 'lib/zip/filesystem/dir.rb', line 48

def glob(*args, &block)
  @mapped_zip.glob(*args, &block)
end

#mkdir(entry_name, permissions = 0o755) ⇒ Object



77
78
79
# File 'lib/zip/filesystem/dir.rb', line 77

def mkdir(entry_name, permissions = 0o755)
  @mapped_zip.mkdir(entry_name, permissions)
end

#new(directory_name) ⇒ Object



12
13
14
# File 'lib/zip/filesystem/dir.rb', line 12

def new(directory_name)
  DirectoryIterator.new(entries(directory_name))
end

#open(directory_name) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/zip/filesystem/dir.rb', line 16

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

#pwdObject Also known as: getwd



29
30
31
# File 'lib/zip/filesystem/dir.rb', line 29

def pwd
  @mapped_zip.pwd
end