Class: FakeFS::File::Stat
- Inherits:
-
Object
- Object
- FakeFS::File::Stat
- Includes:
- Comparable
- Defined in:
- lib/fakefs/file.rb
Overview
FakeFS Stat class
Instance Attribute Summary collapse
-
#atime ⇒ Object
readonly
Returns the value of attribute atime.
-
#birthtime ⇒ Object
readonly
Returns the value of attribute birthtime.
-
#ctime ⇒ Object
readonly
Returns the value of attribute ctime.
-
#gid ⇒ Object
readonly
Returns the value of attribute gid.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #directory? ⇒ Boolean
- #file? ⇒ Boolean
- #ftype ⇒ Object
-
#initialize(file, lstat = false) ⇒ Stat
constructor
A new instance of Stat.
- #ino ⇒ Object
- #nlink ⇒ Object
- #readable? ⇒ Boolean
- #size ⇒ Object
-
#sticky? ⇒ Boolean
Assume nothing is sticky.
- #symlink? ⇒ Boolean
- #world_readable? ⇒ Boolean
-
#world_writable? ⇒ Boolean
World_writable and readable are platform dependent usually comparing with S_IROTH defined on compilation (MRI).
- #writable? ⇒ Boolean
- #zero? ⇒ Boolean
Constructor Details
#initialize(file, lstat = false) ⇒ Stat
Returns a new instance of Stat.
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/fakefs/file.rb', line 369 def initialize(file, lstat = false) raise(Errno::ENOENT, file.to_s) 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 @inode = @fake_file.inode @birthtime = if @fake_file.respond_to?(:birthtime) @fake_file.birthtime else @fake_file.ctime end end |
Instance Attribute Details
#atime ⇒ Object (readonly)
Returns the value of attribute atime.
367 368 369 |
# File 'lib/fakefs/file.rb', line 367 def atime @atime end |
#birthtime ⇒ Object (readonly)
Returns the value of attribute birthtime.
367 368 369 |
# File 'lib/fakefs/file.rb', line 367 def birthtime @birthtime end |
#ctime ⇒ Object (readonly)
Returns the value of attribute ctime.
367 368 369 |
# File 'lib/fakefs/file.rb', line 367 def ctime @ctime end |
#gid ⇒ Object (readonly)
Returns the value of attribute gid.
367 368 369 |
# File 'lib/fakefs/file.rb', line 367 def gid @gid end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
367 368 369 |
# File 'lib/fakefs/file.rb', line 367 def mode @mode end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
367 368 369 |
# File 'lib/fakefs/file.rb', line 367 def mtime @mtime end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
367 368 369 |
# File 'lib/fakefs/file.rb', line 367 def uid @uid end |
Instance Method Details
#<=>(other) ⇒ Object
470 471 472 |
# File 'lib/fakefs/file.rb', line 470 def <=>(other) @mtime <=> other.mtime end |
#directory? ⇒ Boolean
395 396 397 |
# File 'lib/fakefs/file.rb', line 395 def directory? File.directory?(@file) end |
#file? ⇒ Boolean
399 400 401 |
# File 'lib/fakefs/file.rb', line 399 def file? File.file?(@file) end |
#ftype ⇒ Object
403 404 405 406 407 |
# File 'lib/fakefs/file.rb', line 403 def ftype return 'link' if symlink? return 'directory' if directory? 'file' end |
#ino ⇒ Object
464 465 466 |
# File 'lib/fakefs/file.rb', line 464 def ino @inode.inode_num end |
#nlink ⇒ Object
448 449 450 |
# File 'lib/fakefs/file.rb', line 448 def nlink @fake_file.links.size end |
#readable? ⇒ Boolean
409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/fakefs/file.rb', line 409 def readable? # a file is readable if, and only if, it has the following bits: # 4 ( read permission ) # 5 ( read + execute permission ) # 6 ( read + write permission ) # 7 ( read + write + execute permission ) # for each group we will isolate the wanted numbers ( for owner, world, or group ) # and see if the third bit is set ( as that is the bit for read ) read_bit = 4 check_if_bit_set(read_bit) end |
#size ⇒ Object
452 453 454 455 456 457 458 |
# File 'lib/fakefs/file.rb', line 452 def size if @__lstat && symlink? @fake_file.target.size else File.size(@file) end end |
#sticky? ⇒ Boolean
Assume nothing is sticky.
434 435 436 |
# File 'lib/fakefs/file.rb', line 434 def sticky? false end |
#symlink? ⇒ Boolean
391 392 393 |
# File 'lib/fakefs/file.rb', line 391 def symlink? File.symlink?(@file) end |
#world_readable? ⇒ Boolean
444 445 446 |
# File 'lib/fakefs/file.rb', line 444 def world_readable? 0o777 end |
#world_writable? ⇒ Boolean
World_writable and readable are platform dependent usually comparing with S_IROTH defined on compilation (MRI)
440 441 442 |
# File 'lib/fakefs/file.rb', line 440 def world_writable? 0o777 end |
#writable? ⇒ Boolean
421 422 423 424 425 426 427 428 429 430 431 |
# File 'lib/fakefs/file.rb', line 421 def writable? # a file is writable if, and only if, it has the following bits: # 2 ( write permission ) # 3 ( write + execute permission ) # 6 ( read + write permission ) # 7 ( read + write + execute permission ) # for each group we will isolate the wanted numbers ( for owner, world, or group ) # and see if the second bit is set ( as that is the bit for write ) write_bit = 2 check_if_bit_set(write_bit) end |
#zero? ⇒ Boolean
460 461 462 |
# File 'lib/fakefs/file.rb', line 460 def zero? size == 0 end |