Class: MemFs::Fake::Directory
- Inherits:
-
Entry
- Object
- Entry
- MemFs::Fake::Directory
show all
- Defined in:
- lib/memfs/fake/directory.rb
Constant Summary
Constants inherited
from Entry
Entry::GEXEC, Entry::GREAD, Entry::GWRITE, Entry::OEXEC, Entry::OREAD, Entry::OWRITE, Entry::RSTICK, Entry::SETGID, Entry::SETUID, Entry::UEXEC, Entry::UREAD, Entry::USTICK, Entry::UWRITE
Instance Attribute Summary collapse
Attributes inherited from Entry
#atime, #block_device, #character_device, #ctime, #gid, #mode, #mtime, #name, #parent, #uid
Instance Method Summary
collapse
Methods inherited from Entry
#blksize, #delete, #dereferenced, #dereferenced_name, #dereferenced_path, #dev, #ino, #touch
Constructor Details
#initialize(*args) ⇒ Directory
Returns a new instance of Directory.
32
33
34
35
|
# File 'lib/memfs/fake/directory.rb', line 32
def initialize(*args)
super
self.entries = { '.' => self, '..' => nil }
end
|
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
6
7
8
|
# File 'lib/memfs/fake/directory.rb', line 6
def entries
@entries
end
|
Instance Method Details
#add_entry(entry) ⇒ Object
8
9
10
11
|
# File 'lib/memfs/fake/directory.rb', line 8
def add_entry(entry)
entries[entry.name] = entry
entry.parent = self
end
|
#empty? ⇒ Boolean
13
14
15
|
# File 'lib/memfs/fake/directory.rb', line 13
def empty?
(entries.keys - %w[. ..]).empty?
end
|
#entry_names ⇒ Object
17
18
19
|
# File 'lib/memfs/fake/directory.rb', line 17
def entry_names
entries.keys
end
|
#find(path) ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/memfs/fake/directory.rb', line 21
def find(path)
path = path.sub(/\A\/+/, '')
parts = path.split('/', 2)
if entry_names.include?(path)
entries[path]
elsif entry_names.include?(parts.first)
entries[parts.first].find(parts.last)
end
end
|
#parent=(parent) ⇒ Object
37
38
39
40
|
# File 'lib/memfs/fake/directory.rb', line 37
def parent=(parent)
super
entries['..'] = parent
end
|
#path ⇒ Object
42
43
44
|
# File 'lib/memfs/fake/directory.rb', line 42
def path
name == '/' ? '/' : super
end
|
#paths ⇒ Object
46
47
48
|
# File 'lib/memfs/fake/directory.rb', line 46
def paths
[path] + entries.reject { |p| %w[. ..].include?(p) }.values.map(&:paths).flatten
end
|
#remove_entry(entry) ⇒ Object
50
51
52
|
# File 'lib/memfs/fake/directory.rb', line 50
def remove_entry(entry)
entries.delete(entry.name)
end
|
#type ⇒ Object
54
55
56
|
# File 'lib/memfs/fake/directory.rb', line 54
def type
'directory'
end
|