Class: FakeFS::File::Stat

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

Overview

FakeFS Stat class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, lstat = false) ⇒ Stat

Returns a new instance of Stat.



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/fakefs/file.rb', line 315

def initialize(file, lstat = false)
  fail(Errno::ENOENT, file) unless File.exist?(file)

  @file      = file
  @fake_file = FileSystem.find(@file)
  @__lstat   = lstat
  @ctime     = @fake_file.ctime
  @mtime     = @fake_file.mtime
  @atime     = @fake_file.atime
  @mode      = @fake_file.mode
  @uid       = @fake_file.uid
  @gid       = @fake_file.gid
  @birthtime =
    if @fake_file.respond_to?(:birthtime)
      @fake_file.birthtime
    else
      @fake_file.ctime
    end
end

Instance Attribute Details

#atimeObject (readonly)

Returns the value of attribute atime.



312
313
314
# File 'lib/fakefs/file.rb', line 312

def atime
  @atime
end

#birthtimeObject (readonly)

Returns the value of attribute birthtime.



313
314
315
# File 'lib/fakefs/file.rb', line 313

def birthtime
  @birthtime
end

#ctimeObject (readonly)

Returns the value of attribute ctime.



312
313
314
# File 'lib/fakefs/file.rb', line 312

def ctime
  @ctime
end

#gidObject (readonly)

Returns the value of attribute gid.



312
313
314
# File 'lib/fakefs/file.rb', line 312

def gid
  @gid
end

#modeObject (readonly)

Returns the value of attribute mode.



312
313
314
# File 'lib/fakefs/file.rb', line 312

def mode
  @mode
end

#mtimeObject (readonly)

Returns the value of attribute mtime.



312
313
314
# File 'lib/fakefs/file.rb', line 312

def mtime
  @mtime
end

#uidObject (readonly)

Returns the value of attribute uid.



312
313
314
# File 'lib/fakefs/file.rb', line 312

def uid
  @uid
end

Instance Method Details

#<=>(other) ⇒ Object



395
396
397
# File 'lib/fakefs/file.rb', line 395

def <=>(other)
  @mtime <=> other.mtime
end

#directory?Boolean

Returns:

  • (Boolean)


339
340
341
# File 'lib/fakefs/file.rb', line 339

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

#file?Boolean

Returns:

  • (Boolean)


343
344
345
# File 'lib/fakefs/file.rb', line 343

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

#ftypeObject



347
348
349
350
351
# File 'lib/fakefs/file.rb', line 347

def ftype
  return 'link' if symlink?
  return 'directory' if directory?
  'file'
end


377
378
379
# File 'lib/fakefs/file.rb', line 377

def nlink
  @fake_file.links.size
end

#readable?Boolean

assumes, like above, that all files are readable and writable.

Returns:

  • (Boolean)


354
355
356
# File 'lib/fakefs/file.rb', line 354

def readable?
  true
end

#sizeObject



381
382
383
384
385
386
387
# File 'lib/fakefs/file.rb', line 381

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

#sticky?Boolean

Assume nothing is sticky.

Returns:

  • (Boolean)


363
364
365
# File 'lib/fakefs/file.rb', line 363

def sticky?
  false
end

#symlink?Boolean

Returns:

  • (Boolean)


335
336
337
# File 'lib/fakefs/file.rb', line 335

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

#world_readable?Boolean

Returns:

  • (Boolean)


373
374
375
# File 'lib/fakefs/file.rb', line 373

def world_readable?
  0777
end

#world_writable?Boolean

World_writable and readable are platform dependent usually comparing with S_IROTH defined on compilation (MRI)

Returns:

  • (Boolean)


369
370
371
# File 'lib/fakefs/file.rb', line 369

def world_writable?
  0777
end

#writable?Boolean

Returns:

  • (Boolean)


358
359
360
# File 'lib/fakefs/file.rb', line 358

def writable?
  true
end

#zero?Boolean

Returns:

  • (Boolean)


389
390
391
# File 'lib/fakefs/file.rb', line 389

def zero?
  size == 0
end