Class: FakeFS::File::Stat

Inherits:
Object
  • Object
show all
Defined in:
lib/fakefs/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, __lstat = false) ⇒ Stat

Returns a new instance of Stat.



192
193
194
195
196
197
198
199
200
201
202
# File 'lib/fakefs/file.rb', line 192

def initialize(file, __lstat = false)
  if !File.exists?(file)
    raise(Errno::ENOENT, "No such file or directory - #{file}")
  end

  @file      = file
  @fake_file = FileSystem.find(@file)
  @__lstat   = __lstat
  @ctime     = @fake_file.ctime
  @mtime     = @fake_file.mtime
end

Instance Attribute Details

#ctimeObject (readonly)

Returns the value of attribute ctime.



190
191
192
# File 'lib/fakefs/file.rb', line 190

def ctime
  @ctime
end

#mtimeObject (readonly)

Returns the value of attribute mtime.



190
191
192
# File 'lib/fakefs/file.rb', line 190

def mtime
  @mtime
end

Instance Method Details

#directory?Boolean

Returns:

  • (Boolean)


208
209
210
# File 'lib/fakefs/file.rb', line 208

def directory?
  File.directory?(@file)
end


212
213
214
# File 'lib/fakefs/file.rb', line 212

def nlink
  @fake_file.links.size
end

#sizeObject



216
217
218
219
220
221
222
# File 'lib/fakefs/file.rb', line 216

def size
  if @__lstat && symlink?
    @fake_file.target.size
  else
    File.size(@file)
  end
end

#symlink?Boolean

Returns:

  • (Boolean)


204
205
206
# File 'lib/fakefs/file.rb', line 204

def symlink?
  File.symlink?(@file)
end