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.
- #nlink ⇒ Object
-
#readable? ⇒ Boolean
assumes, like above, that all files are readable and writable.
- #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.
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/fakefs/file.rb', line 310 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
#atime ⇒ Object (readonly)
Returns the value of attribute atime.
307 308 309 |
# File 'lib/fakefs/file.rb', line 307 def atime @atime end |
#birthtime ⇒ Object (readonly)
Returns the value of attribute birthtime.
308 309 310 |
# File 'lib/fakefs/file.rb', line 308 def birthtime @birthtime end |
#ctime ⇒ Object (readonly)
Returns the value of attribute ctime.
307 308 309 |
# File 'lib/fakefs/file.rb', line 307 def ctime @ctime end |
#gid ⇒ Object (readonly)
Returns the value of attribute gid.
307 308 309 |
# File 'lib/fakefs/file.rb', line 307 def gid @gid end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
307 308 309 |
# File 'lib/fakefs/file.rb', line 307 def mode @mode end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
307 308 309 |
# File 'lib/fakefs/file.rb', line 307 def mtime @mtime end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
307 308 309 |
# File 'lib/fakefs/file.rb', line 307 def uid @uid end |
Instance Method Details
#<=>(other) ⇒ Object
390 391 392 |
# File 'lib/fakefs/file.rb', line 390 def <=>(other) @mtime <=> other.mtime end |
#directory? ⇒ Boolean
334 335 336 |
# File 'lib/fakefs/file.rb', line 334 def directory? File.directory?(@file) end |
#ftype ⇒ Object
342 343 344 345 346 |
# File 'lib/fakefs/file.rb', line 342 def ftype return 'link' if symlink? return 'directory' if directory? 'file' end |
#nlink ⇒ Object
372 373 374 |
# File 'lib/fakefs/file.rb', line 372 def nlink @fake_file.links.size end |
#readable? ⇒ Boolean
assumes, like above, that all files are readable and writable.
349 350 351 |
# File 'lib/fakefs/file.rb', line 349 def readable? true end |
#size ⇒ Object
376 377 378 379 380 381 382 |
# File 'lib/fakefs/file.rb', line 376 def size if @__lstat && symlink? @fake_file.target.size else File.size(@file) end end |
#sticky? ⇒ Boolean
Assume nothing is sticky.
358 359 360 |
# File 'lib/fakefs/file.rb', line 358 def sticky? false end |
#symlink? ⇒ Boolean
330 331 332 |
# File 'lib/fakefs/file.rb', line 330 def symlink? File.symlink?(@file) end |
#world_readable? ⇒ Boolean
368 369 370 |
# File 'lib/fakefs/file.rb', line 368 def world_readable? 0777 end |
#world_writable? ⇒ Boolean
World_writable and readable are platform dependent usually comparing with S_IROTH defined on compilation (MRI)
364 365 366 |
# File 'lib/fakefs/file.rb', line 364 def world_writable? 0777 end |
#writable? ⇒ Boolean
353 354 355 |
# File 'lib/fakefs/file.rb', line 353 def writable? true end |
#zero? ⇒ Boolean
384 385 386 |
# File 'lib/fakefs/file.rb', line 384 def zero? size == 0 end |