Class: Redisk::Stat
- Inherits:
-
Object
- Object
- Redisk::Stat
- Extended by:
- Helper
- Includes:
- Comparable, Helper
- Defined in:
- lib/redisk/stat.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#<=>(other_stat) ⇒ Object
stat <=> other_stat => -1, 0, 1 Compares File::Stat objects by comparing their respective modification times.
-
#atime ⇒ Object
stat.atime => time Returns the last access time for this file as an object of class Time.
-
#blksize ⇒ Object
stat.blksize => integer or nil Returns the native file system‘s block size.
-
#blockdev? ⇒ Boolean
stat.blockdev? => true or false Returns true if the file is a block device, false if it isn‘t or if the operating system doesn‘t support this feature.
-
#blocks ⇒ Object
stat.blocks => integer or nil Returns the number of native file system blocks allocated for this file, or nil if the operating system doesn‘t support this feature.
-
#chardev? ⇒ Boolean
stat.chardev? => true or false Returns true if the file is a character device, false if it isn‘t or if the operating system doesn‘t support this feature.
-
#ctime ⇒ Object
stat.ctime → aTime Returns the change time for stat (that is, the time directory information about the file was changed, not the file itself).
-
#dev ⇒ Object
stat.dev => fixnum Returns an integer representing the device on which stat resides.
-
#dev_major ⇒ Object
stat.dev_major => fixnum Returns the major part of File_Stat#dev or nil.
-
#dev_minor ⇒ Object
stat.dev_minor => fixnum Returns the minor part of File_Stat#dev or nil.
-
#directory? ⇒ Boolean
stat.directory? => true or false Returns true if stat is a directory, false otherwise.
-
#executable? ⇒ Boolean
stat.executable? => true or false Returns true if stat is executable or if the operating system doesn‘t distinguish executable files from nonexecutable files.
-
#executable_real? ⇒ Boolean
stat.executable_real? => true or false Same as executable?, but tests using the real owner of the process.
-
#file? ⇒ Boolean
stat.file? => true or false Returns true if stat is a regular file (not a device file, pipe, socket, etc.).
-
#ftype ⇒ Object
stat.ftype => string Identifies the type of stat.
-
#gid ⇒ Object
stat.gid => fixnum Returns the numeric group id of the owner of stat.
-
#grpowned? ⇒ Boolean
stat.grpowned? => true or false Returns true if the effective group id of the process is the same as the group id of stat.
-
#initialize(name) ⇒ Stat
constructor
A new instance of Stat.
-
#ino ⇒ Object
stat.ino => fixnum Returns the inode number for stat.
-
#inspect ⇒ Object
(also: #to_s)
stat.inspect => string Produce a nicely formatted description of stat.
-
#mode ⇒ Object
stat.mode => fixnum Returns an integer representing the permission bits of stat.
-
#mtime ⇒ Object
stat.mtime → aTime Returns the modification time of stat.
-
#nlink ⇒ Object
stat.nlink => fixnum Returns the number of hard links to stat.
-
#owned? ⇒ Boolean
stat.owned? => true or false Returns true if the effective user id of the process is the same as the owner of stat.
-
#pipe ⇒ Object
stat.pipe? => true or false Returns true if the operating system supports pipes and stat is a pipe; false otherwise.
-
#rdev ⇒ Object
stat.rdev => fixnum or nil Returns an integer representing the device type on which stat resides.
-
#rdev_major ⇒ Object
stat.rdev_major => fixnum Returns the major part of File_Stat#rdev or nil.
-
#rdev_minor ⇒ Object
stat.rdev_minor => fixnum Returns the minor part of File_Stat#rdev or nil.
-
#read_attribute(key) ⇒ Object
reads the attribute from Redis or returns nil.
-
#readable? ⇒ Boolean
stat.readable? => true or false Returns true if stat is readable by the effective user id of this process.
-
#readable_real? ⇒ Boolean
stat.readable_real? → true or false Returns true if stat is readable by the real user id of this process.
-
#setgid? ⇒ Boolean
stat.setgid? => true or false Returns true if stat has the set-group-id permission bit set, false if it doesn‘t or if the operating system doesn‘t support this feature.
-
#setuid? ⇒ Boolean
stat.setuid? => true or false Returns true if stat has the set-user-id permission bit set, false if it doesn‘t or if the operating system doesn‘t support this feature.
-
#size ⇒ Object
stat.size => fixnum Returns the size of stat in bytes.
-
#socket ⇒ Object
stat.socket? => true or false Returns true if stat is a socket, false if it isn‘t or if the operating system doesn‘t support this feature.
-
#sticky ⇒ Object
stat.sticky? => true or false Returns true if stat has its sticky bit set, false if it doesn‘t or if the operating system doesn‘t support this feature.
-
#symlink? ⇒ Boolean
stat.symlink? => true or false Returns true if stat is a symbolic link, false if it isn‘t or if the operating system doesn‘t support this feature.
-
#uid ⇒ Object
stat.uid => fixnum Returns the numeric user id of the owner of stat.
-
#writable? ⇒ Boolean
stat.writable? → true or false Returns true if stat is writable by the effective user id of this process.
-
#writable_real? ⇒ Boolean
stat.writable_real? → true or false Returns true if stat is writable by the real user id of this process.
-
#write_attribute(key, value) ⇒ Object
writes the attribute to redis as a string.
-
#write_default(key, value) ⇒ Object
writes the default if this is the first time for this file.
-
#zero? ⇒ Boolean
stat.zero? => true or false Returns true if stat is a zero-length file; false otherwise.
Methods included from Helper
Constructor Details
#initialize(name) ⇒ Stat
Returns a new instance of Stat.
13 14 15 16 17 18 19 |
# File 'lib/redisk/stat.rb', line 13 def initialize(name) @name = name write_default('atime', Time.now) write_default('ctime', Time.now) write_default('mtime', Time.now) write_default('size', 0) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/redisk/stat.rb', line 11 def name @name end |
Instance Method Details
#<=>(other_stat) ⇒ Object
stat <=> other_stat => -1, 0, 1 Compares File::Stat objects by comparing their respective modification times.
f1 = File.new("f1", "w")
sleep 1
f2 = File.new("f2", "w")
f1.stat <=> f2.stat #=> -1
28 29 30 |
# File 'lib/redisk/stat.rb', line 28 def <=>(other_stat) self.mtime <=> other_stat.mtime end |
#atime ⇒ Object
stat.atime => time Returns the last access time for this file as an object of class Time.
File.stat("testfile").atime #=> Wed Dec 31 18:00:00 CST 1969
36 37 38 |
# File 'lib/redisk/stat.rb', line 36 def atime Time.parse(read_attribute('atime')) end |
#blksize ⇒ Object
stat.blksize => integer or nil Returns the native file system‘s block size. Will return nil on platforms that don‘t support this information.
File.stat("testfile").blksize #=> 4096
44 45 46 |
# File 'lib/redisk/stat.rb', line 44 def blksize 0 end |
#blockdev? ⇒ Boolean
stat.blockdev? => true or false Returns true if the file is a block device, false if it isn‘t or if the operating system doesn‘t support this feature.
File.stat("testfile").blockdev? #=> false
File.stat("/dev/hda1").blockdev? #=> true
53 54 55 |
# File 'lib/redisk/stat.rb', line 53 def blockdev? false end |
#blocks ⇒ Object
stat.blocks => integer or nil Returns the number of native file system blocks allocated for this file, or nil if the operating system doesn‘t support this feature.
File.stat("testfile").blocks #=> 2
61 62 63 |
# File 'lib/redisk/stat.rb', line 61 def blocks 0 end |
#chardev? ⇒ Boolean
stat.chardev? => true or false Returns true if the file is a character device, false if it isn‘t or if the operating system doesn‘t support this feature.
File.stat("/dev/tty").chardev? #=> true
69 70 71 |
# File 'lib/redisk/stat.rb', line 69 def chardev? false end |
#ctime ⇒ Object
stat.ctime → aTime Returns the change time for stat (that is, the time directory information about the file was changed, not the file itself).
File.stat("testfile").ctime #=> Wed Apr 09 08:53:14 CDT 2003
77 78 79 |
# File 'lib/redisk/stat.rb', line 77 def ctime Time.parse(read_attribute('ctime')) end |
#dev ⇒ Object
stat.dev => fixnum Returns an integer representing the device on which stat resides.
File.stat("testfile").dev #=> 774
85 86 87 |
# File 'lib/redisk/stat.rb', line 85 def dev nil end |
#dev_major ⇒ Object
stat.dev_major => fixnum Returns the major part of File_Stat#dev or nil.
File.stat("/dev/fd1").dev_major #=> 2
File.stat("/dev/tty").dev_major #=> 5
94 95 96 |
# File 'lib/redisk/stat.rb', line 94 def dev_major 0 end |
#dev_minor ⇒ Object
stat.dev_minor => fixnum Returns the minor part of File_Stat#dev or nil.
File.stat("/dev/fd1").dev_minor #=> 1
File.stat("/dev/tty").dev_minor #=> 0
103 104 105 |
# File 'lib/redisk/stat.rb', line 103 def dev_minor 0 end |
#directory? ⇒ Boolean
stat.directory? => true or false Returns true if stat is a directory, false otherwise.
File.stat("testfile").directory? #=> false
File.stat(".").directory? #=> true
112 113 114 |
# File 'lib/redisk/stat.rb', line 112 def directory? false end |
#executable? ⇒ Boolean
stat.executable? => true or false Returns true if stat is executable or if the operating system doesn‘t distinguish executable files from nonexecutable files. The tests are made using the effective owner of the process.
File.stat("testfile").executable? #=> false
120 121 122 |
# File 'lib/redisk/stat.rb', line 120 def executable? false end |
#executable_real? ⇒ Boolean
stat.executable_real? => true or false Same as executable?, but tests using the real owner of the process.
126 127 128 |
# File 'lib/redisk/stat.rb', line 126 def executable_real? false end |
#file? ⇒ Boolean
stat.file? => true or false Returns true if stat is a regular file (not a device file, pipe, socket, etc.).
File.stat("testfile").file? #=> true
134 135 136 |
# File 'lib/redisk/stat.rb', line 134 def file? false end |
#ftype ⇒ Object
stat.ftype => string Identifies the type of stat. The return string is one of: “file’’, “directory’’, “characterSpecial’’, “blockSpecial’’, “fifo’’, “link’’, “socket’’, or “unknown’’.
File.stat("/dev/tty").ftype #=> "characterSpecial"
142 143 144 |
# File 'lib/redisk/stat.rb', line 142 def ftype 'unknown' end |
#gid ⇒ Object
stat.gid => fixnum Returns the numeric group id of the owner of stat.
File.stat("testfile").gid #=> 500
150 151 152 |
# File 'lib/redisk/stat.rb', line 150 def gid Process.gid end |
#grpowned? ⇒ Boolean
stat.grpowned? => true or false Returns true if the effective group id of the process is the same as the group id of stat. On Windows NT, returns false.
File.stat("testfile").grpowned? #=> true
File.stat("/etc/passwd").grpowned? #=> false
159 160 161 |
# File 'lib/redisk/stat.rb', line 159 def grpowned? Process.grpowned? end |
#ino ⇒ Object
stat.ino => fixnum Returns the inode number for stat.
File.stat("testfile").ino #=> 1083669
167 168 169 |
# File 'lib/redisk/stat.rb', line 167 def ino Process.ino end |
#inspect ⇒ Object Also known as: to_s
stat.inspect => string Produce a nicely formatted description of stat.
File.stat("/etc/passwd").inspect
#=> "#<File::Stat dev=0xe000005, ino=1078078, mode=0100644,
nlink=1, uid=0, gid=0, rdev=0x0, size=1374, blksize=4096,
blocks=8, atime=Wed Dec 10 10:16:12 CST 2003,
mtime=Fri Sep 12 15:41:41 CDT 2003,
ctime=Mon Oct 27 11:20:27 CST 2003>"
180 181 182 |
# File 'lib/redisk/stat.rb', line 180 def inspect "#<Redis::Stat (#{name}) atime=#{atime}, ctime=#{ctime}, mtime=#{mtime}, size=#{size}" end |
#mode ⇒ Object
stat.mode => fixnum Returns an integer representing the permission bits of stat. The meaning of the bits is platform dependent; on Unix systems, see stat(2).
File.chmod(0644, "testfile") #=> 1
s = File.stat("testfile")
sprintf("%o", s.mode) #=> "100644"
191 192 193 |
# File 'lib/redisk/stat.rb', line 191 def mode Process.mode end |
#mtime ⇒ Object
stat.mtime → aTime Returns the modification time of stat.
File.stat("testfile").mtime #=> Wed Apr 09 08:53:14 CDT 2003
199 200 201 |
# File 'lib/redisk/stat.rb', line 199 def mtime Time.parse(read_attribute('mtime')) end |
#nlink ⇒ Object
stat.nlink => fixnum Returns the number of hard links to stat.
File.stat("testfile").nlink #=> 1
File.link("testfile", "testfile.bak") #=> 0
File.stat("testfile").nlink #=> 2
209 210 211 |
# File 'lib/redisk/stat.rb', line 209 def nlink 0 end |
#owned? ⇒ Boolean
stat.owned? => true or false Returns true if the effective user id of the process is the same as the owner of stat.
File.stat("testfile").owned? #=> true
File.stat("/etc/passwd").owned? #=> false
218 219 220 |
# File 'lib/redisk/stat.rb', line 218 def owned? true end |
#pipe ⇒ Object
stat.pipe? => true or false Returns true if the operating system supports pipes and stat is a pipe; false otherwise.
224 225 226 |
# File 'lib/redisk/stat.rb', line 224 def pipe false end |
#rdev ⇒ Object
stat.rdev => fixnum or nil Returns an integer representing the device type on which stat resides. Returns nil if the operating system doesn‘t support this feature.
File.stat("/dev/fd1").rdev #=> 513
File.stat("/dev/tty").rdev #=> 1280
233 234 235 |
# File 'lib/redisk/stat.rb', line 233 def rdev 0 end |
#rdev_major ⇒ Object
stat.rdev_major => fixnum Returns the major part of File_Stat#rdev or nil.
File.stat("/dev/fd1").rdev_major #=> 2
File.stat("/dev/tty").rdev_major #=> 5
242 243 244 |
# File 'lib/redisk/stat.rb', line 242 def rdev_major 0 end |
#rdev_minor ⇒ Object
stat.rdev_minor => fixnum Returns the minor part of File_Stat#rdev or nil.
File.stat("/dev/fd1").rdev_minor #=> 1
File.stat("/dev/tty").rdev_minor #=> 0
251 252 253 |
# File 'lib/redisk/stat.rb', line 251 def rdev_minor 0 end |
#read_attribute(key) ⇒ Object
reads the attribute from Redis or returns nil
357 358 359 360 |
# File 'lib/redisk/stat.rb', line 357 def read_attribute(key) write_attribute('atime', Time.now) redis.get key_for_attribute(key) end |
#readable? ⇒ Boolean
stat.readable? => true or false Returns true if stat is readable by the effective user id of this process.
File.stat("testfile").readable? #=> true
259 260 261 |
# File 'lib/redisk/stat.rb', line 259 def readable? true end |
#readable_real? ⇒ Boolean
stat.readable_real? → true or false Returns true if stat is readable by the real user id of this process.
File.stat("testfile").readable_real? #=> true
267 268 269 |
# File 'lib/redisk/stat.rb', line 267 def readable_real? true end |
#setgid? ⇒ Boolean
stat.setgid? => true or false Returns true if stat has the set-group-id permission bit set, false if it doesn‘t or if the operating system doesn‘t support this feature.
File.stat("/usr/sbin/lpc").setgid? #=> true
275 276 277 |
# File 'lib/redisk/stat.rb', line 275 def setgid? Process.setgid? end |
#setuid? ⇒ Boolean
stat.setuid? => true or false Returns true if stat has the set-user-id permission bit set, false if it doesn‘t or if the operating system doesn‘t support this feature.
File.stat("/bin/su").setuid? #=> true
283 284 285 |
# File 'lib/redisk/stat.rb', line 283 def setuid? Process.setuid? end |
#size ⇒ Object
stat.size => fixnum Returns the size of stat in bytes.
File.stat("testfile").size #=> 66
291 292 293 |
# File 'lib/redisk/stat.rb', line 291 def size read_attribute('size').to_i end |
#socket ⇒ Object
stat.socket? => true or false Returns true if stat is a socket, false if it isn‘t or if the operating system doesn‘t support this feature.
File.stat("testfile").socket? #=> false
299 300 301 |
# File 'lib/redisk/stat.rb', line 299 def socket false end |
#sticky ⇒ Object
stat.sticky? => true or false Returns true if stat has its sticky bit set, false if it doesn‘t or if the operating system doesn‘t support this feature.
File.stat("testfile").sticky? #=> false
307 308 309 |
# File 'lib/redisk/stat.rb', line 307 def sticky false end |
#symlink? ⇒ Boolean
stat.symlink? => true or false Returns true if stat is a symbolic link, false if it isn‘t or if the operating system doesn‘t support this feature. As File::stat automatically follows symbolic links, symlink? will always be false for an object returned by File::stat.
File.symlink("testfile", "alink") #=> 0
File.stat("alink").symlink? #=> false
File.lstat("alink").symlink? #=> true
317 318 319 |
# File 'lib/redisk/stat.rb', line 317 def symlink? false end |
#uid ⇒ Object
stat.uid => fixnum Returns the numeric user id of the owner of stat.
File.stat("testfile").uid #=> 501
326 327 328 |
# File 'lib/redisk/stat.rb', line 326 def uid Process.uid end |
#writable? ⇒ Boolean
stat.writable? → true or false Returns true if stat is writable by the effective user id of this process.
File.stat("testfile").writable? #=> true
334 335 336 |
# File 'lib/redisk/stat.rb', line 334 def writable? true end |
#writable_real? ⇒ Boolean
stat.writable_real? → true or false Returns true if stat is writable by the real user id of this process.
File.stat("testfile").writable_real? #=> true
342 343 344 |
# File 'lib/redisk/stat.rb', line 342 def writable_real? true end |
#write_attribute(key, value) ⇒ Object
writes the attribute to redis as a string
363 364 365 366 367 |
# File 'lib/redisk/stat.rb', line 363 def write_attribute(key, value) redis.set key_for_attribute(key), value.to_s redis.set key_for_attribute('ctime'), Time.now value.to_s end |
#write_default(key, value) ⇒ Object
writes the default if this is the first time for this file
370 371 372 |
# File 'lib/redisk/stat.rb', line 370 def write_default(key, value) redis.setnx key_for_attribute(key), value.to_s end |
#zero? ⇒ Boolean
stat.zero? => true or false Returns true if stat is a zero-length file; false otherwise.
File.stat("testfile").zero? #=> false
350 351 352 |
# File 'lib/redisk/stat.rb', line 350 def zero? size == 0 end |