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.



221
222
223
224
225
226
227
228
229
230
231
# File 'lib/fakefs/file.rb', line 221

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.



219
220
221
# File 'lib/fakefs/file.rb', line 219

def ctime
  @ctime
end

#mtimeObject (readonly)

Returns the value of attribute mtime.



219
220
221
# File 'lib/fakefs/file.rb', line 219

def mtime
  @mtime
end

Instance Method Details

#directory?Boolean

Returns:

  • (Boolean)


237
238
239
# File 'lib/fakefs/file.rb', line 237

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


241
242
243
# File 'lib/fakefs/file.rb', line 241

def nlink
  @fake_file.links.size
end

#sizeObject



245
246
247
248
249
250
251
# File 'lib/fakefs/file.rb', line 245

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

#symlink?Boolean

Returns:

  • (Boolean)


233
234
235
# File 'lib/fakefs/file.rb', line 233

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