Sha256: 6ca83e9c71879e7cfcfa07c8952b6e9263d0876df07a2a0bc20ebc5a578a9ba2
Contents?: true
Size: 1.46 KB
Versions: 4
Compression:
Stored size: 1.46 KB
Contents
module FakeFS # Fake Dir class class FakeDir attr_accessor :name, :parent, :mode, :uid, :gid, :mtime, :atime attr_reader :ctime, :content 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 @content = '' @entries = {} end def entry self end def inspect "(FakeDir name:#{name.inspect} " \ "parent:#{parent.to_s.inspect} size:#{@entries.size})" end 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 end def to_s if parent && parent.to_s != '.' File.join(parent.to_s, name) elsif parent && parent.to_s == '.' "#{File::PATH_SEPARATOR}#{name}" else name end end def empty? @entries.empty? end def entries @entries.values end def matches(pattern) @entries.select { |k, _v| pattern =~ k }.values end def [](name) @entries[name] end def []=(name, value) @entries[name] = value end def delete(node = self) if node == self parent.delete(self) else @entries.delete(node.name) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
fakefs-0.14.3 | lib/fakefs/fake/dir.rb |
fakefs-0.14.2 | lib/fakefs/fake/dir.rb |
fakefs-0.14.1 | lib/fakefs/fake/dir.rb |
fakefs-0.14.0 | lib/fakefs/fake/dir.rb |