Sha256: 313392781560920ce7dddf88c1418898645419d080bad351ace7e4369404811c

Contents?: true

Size: 950 Bytes

Versions: 5

Compression:

Stored size: 950 Bytes

Contents

module FakeFS
  class FakeDir < Hash
    attr_accessor :name, :parent
    attr_reader :ctime, :mtime

    def initialize(name = nil, parent = nil)
      @name   = name
      @parent = parent
      @ctime  = Time.now
      @mtime  = @ctime
    end

    def entry
      self
    end

    def inspect
      "(FakeDir name:#{name.inspect} parent:#{parent.to_s.inspect} size:#{size})"
    end

    def clone(parent = nil)
      clone = Marshal.load(Marshal.dump(self))
      clone.each do |key, 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 delete(node = self)
      if node == self
        parent.delete(self)
      else
        super(node.name)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
fakefs-0.4.0 lib/fakefs/fake/dir.rb
fakefs-0.3.2 lib/fakefs/fake/dir.rb
mnoble-fakefs-0.3.2 lib/fakefs/fake/dir.rb
mnoble-fakefs-0.3.1 lib/fakefs/fake/dir.rb
fakefs-0.3.1 lib/fakefs/fake/dir.rb