Sha256: 81083db61995e5246e4f6da256988ba161931df7595571add806af9710c4186a

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

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

    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

    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

1 entries across 1 versions & 1 rubygems

Version Path
fakefs-3.0.0 lib/fakefs/fake/file.rb