Class: FakeFS::FakeDir
- Inherits:
-
Object
- Object
- FakeFS::FakeDir
- Defined in:
- lib/fakefs/fake/dir.rb
Overview
Fake Dir class
Instance Attribute Summary collapse
-
#atime ⇒ Object
Returns the value of attribute atime.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#ctime ⇒ Object
readonly
Returns the value of attribute ctime.
-
#gid ⇒ Object
Returns the value of attribute gid.
-
#inode ⇒ Object
Returns the value of attribute inode.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#mtime ⇒ Object
Returns the value of attribute mtime.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#uid ⇒ Object
Returns the value of attribute uid.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #clone(parent = nil) ⇒ Object
- #delete(node = self) ⇒ Object
- #empty? ⇒ Boolean
- #entries ⇒ Object
- #entry ⇒ Object
-
#initialize(name = nil, parent = nil) ⇒ FakeDir
constructor
A new instance of FakeDir.
- #inspect ⇒ Object
- #matches(pattern) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name = nil, parent = nil) ⇒ FakeDir
Returns a new instance of FakeDir.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/fakefs/fake/dir.rb', line 7 def initialize(name = nil, parent = nil) @name = name @parent = parent @ctime = Time.now @mtime = @ctime @atime = @ctime @mode = 0o100000 + (0o777 - File.umask) @uid = Process.uid @gid = Process.gid @inode = FakeInode.new(self) @content = '' @entries = {} end |
Instance Attribute Details
#atime ⇒ Object
Returns the value of attribute atime.
4 5 6 |
# File 'lib/fakefs/fake/dir.rb', line 4 def atime @atime end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
5 6 7 |
# File 'lib/fakefs/fake/dir.rb', line 5 def content @content end |
#ctime ⇒ Object (readonly)
Returns the value of attribute ctime.
5 6 7 |
# File 'lib/fakefs/fake/dir.rb', line 5 def ctime @ctime end |
#gid ⇒ Object
Returns the value of attribute gid.
4 5 6 |
# File 'lib/fakefs/fake/dir.rb', line 4 def gid @gid end |
#inode ⇒ Object
Returns the value of attribute inode.
4 5 6 |
# File 'lib/fakefs/fake/dir.rb', line 4 def inode @inode end |
#mode ⇒ Object
Returns the value of attribute mode.
4 5 6 |
# File 'lib/fakefs/fake/dir.rb', line 4 def mode @mode end |
#mtime ⇒ Object
Returns the value of attribute mtime.
4 5 6 |
# File 'lib/fakefs/fake/dir.rb', line 4 def mtime @mtime end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/fakefs/fake/dir.rb', line 4 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
4 5 6 |
# File 'lib/fakefs/fake/dir.rb', line 4 def parent @parent end |
#uid ⇒ Object
Returns the value of attribute uid.
4 5 6 |
# File 'lib/fakefs/fake/dir.rb', line 4 def uid @uid end |
Instance Method Details
#[](name) ⇒ Object
62 63 64 |
# File 'lib/fakefs/fake/dir.rb', line 62 def [](name) @entries[name] end |
#[]=(name, value) ⇒ Object
66 67 68 |
# File 'lib/fakefs/fake/dir.rb', line 66 def []=(name, value) @entries[name] = value end |
#clone(parent = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/fakefs/fake/dir.rb', line 30 def clone(parent = nil) clone = Marshal.load(Marshal.dump(self)) clone.entries.each do |value| value.parent = clone end clone.parent = parent if parent clone.inode = @inode.clone clone end |
#delete(node = self) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/fakefs/fake/dir.rb', line 70 def delete(node = self) if node == self parent.delete(self) @inode.free_inode_num else @entries.delete(node.name) end end |
#empty? ⇒ Boolean
50 51 52 |
# File 'lib/fakefs/fake/dir.rb', line 50 def empty? @entries.empty? end |
#entries ⇒ Object
54 55 56 |
# File 'lib/fakefs/fake/dir.rb', line 54 def entries @entries.values end |
#entry ⇒ Object
21 22 23 |
# File 'lib/fakefs/fake/dir.rb', line 21 def entry self end |
#inspect ⇒ Object
25 26 27 28 |
# File 'lib/fakefs/fake/dir.rb', line 25 def inspect "(FakeDir name:#{name.inspect} " \ "parent:#{parent.to_s.inspect} size:#{@entries.size})" end |
#matches(pattern) ⇒ Object
58 59 60 |
# File 'lib/fakefs/fake/dir.rb', line 58 def matches(pattern) @entries.select { |k, _v| pattern =~ k }.values end |