Sha256: 95c40ea6a02f816ee7be9a646332ded66c5e342610df779b8592a38533e0709e

Contents?: true

Size: 1.2 KB

Versions: 37

Compression:

Stored size: 1.2 KB

Contents

module FakeFS
  # Fake file class
  class FakeFile
    attr_accessor :name, :parent, :mtime, :atime, :mode, :uid, :gid
    attr_reader :ctime, :birthtime

    def initialize(name = nil, parent = nil)
      @name      = name
      @parent    = parent
      @inode     = FakeInode.new(self)
      @ctime     = Time.now
      @mtime     = @ctime
      @atime     = @ctime
      @birthtime = @ctime
      @mode      = 0o100000 + (0o666 - File.umask)
      @uid       = Process.uid
      @gid       = Process.gid
    end

    attr_accessor :inode

    def content
      @inode.content
    end

    def content=(str)
      @inode.content = str
    end

    def links
      @inode.links
    end

    def link(other_file)
      @inode.link(other_file)
    end

    def clone(parent = nil)
      clone = super()
      clone.parent = parent if parent
      clone.inode  = inode.clone
      clone
    end

    def entry
      self
    end

    def inspect
      "(FakeFile name:#{name.inspect} " \
      "parent:#{parent.to_s.inspect} size:#{content.size})"
    end

    def to_s
      File.join(parent.to_s, name)
    end

    def delete
      inode.unlink(self)
      inode.free_inode_num
      parent.delete(self)
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
fakefs-2.8.0 lib/fakefs/fake/file.rb
fakefs-2.7.1 lib/fakefs/fake/file.rb
fakefs-2.7.0 lib/fakefs/fake/file.rb
fakefs-2.6.0 lib/fakefs/fake/file.rb
fakefs-2.5.0 lib/fakefs/fake/file.rb
fakefs-2.4.0 lib/fakefs/fake/file.rb
fakefs-2.3.0 lib/fakefs/fake/file.rb
fakefs-2.2.0 lib/fakefs/fake/file.rb
fakefs-2.1.0 lib/fakefs/fake/file.rb
fakefs-2.0.0 lib/fakefs/fake/file.rb
fakefs-1.9.0 lib/fakefs/fake/file.rb
fakefs-1.8.0 lib/fakefs/fake/file.rb
fakefs-1.7.0 lib/fakefs/fake/file.rb
fakefs-1.6.0 lib/fakefs/fake/file.rb
fakefs-1.5.1 lib/fakefs/fake/file.rb
fakefs-1.5.0 lib/fakefs/fake/file.rb
fakefs-1.4.1 lib/fakefs/fake/file.rb
fakefs-1.4.0 lib/fakefs/fake/file.rb
fakefs-1.3.2 lib/fakefs/fake/file.rb
fakefs-1.3.1 lib/fakefs/fake/file.rb