Class: DirectoryWatcher::FileStat
- Inherits:
-
Object
- Object
- DirectoryWatcher::FileStat
- Defined in:
- lib/directory_watcher/file_stat.rb
Overview
FileStat contains file system information about a single file including:
path - The fully expanded path of the file mtime - The last modified time of the file, as a Time object size - The size of the file, in bytes.
The FileStat object can also say if the file is removed of not.
Instance Attribute Summary collapse
-
#mtime ⇒ Object
The last modified time of the file.
-
#path ⇒ Object
readonly
The fully expanded path of the file.
-
#size ⇒ Object
The size of the file in bytes.
Class Method Summary collapse
-
.for_removed_path(path) ⇒ Object
Create an instance of FileStat that will make sure that the instance method
removed?
returns true when called on it.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
(also: #==)
Compare this FileStat to another object.
-
#initialize(path, mtime, size) ⇒ FileStat
constructor
Create a new instance of FileStat with the given path, mtime and size.
-
#removed? ⇒ Boolean
Is the file represented by this FileStat to be considered removed?.
-
#to_s ⇒ Object
Create a nice string based representation of this instance.
Constructor Details
#initialize(path, mtime, size) ⇒ FileStat
Create a new instance of FileStat with the given path, mtime and size
29 30 31 32 33 |
# File 'lib/directory_watcher/file_stat.rb', line 29 def initialize( path, mtime, size ) @path = path @mtime = mtime @size = size end |
Instance Attribute Details
#mtime ⇒ Object
The last modified time of the file
15 16 17 |
# File 'lib/directory_watcher/file_stat.rb', line 15 def mtime @mtime end |
#path ⇒ Object (readonly)
The fully expanded path of the file
12 13 14 |
# File 'lib/directory_watcher/file_stat.rb', line 12 def path @path end |
#size ⇒ Object
The size of the file in bytes
18 19 20 |
# File 'lib/directory_watcher/file_stat.rb', line 18 def size @size end |
Class Method Details
.for_removed_path(path) ⇒ Object
Create an instance of FileStat that will make sure that the instance method removed?
returns true when called on it.
23 24 25 |
# File 'lib/directory_watcher/file_stat.rb', line 23 def self.for_removed_path( path ) ::DirectoryWatcher::FileStat.new(path, nil, nil) end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
Compare this FileStat to another object.
This will only return true when all of the following are true:
1) The other object is also a FileStat object 2) The other object’s mtime is equal to this mtime 3) The other object’s msize is equal to this size
54 55 56 57 |
# File 'lib/directory_watcher/file_stat.rb', line 54 def eql?( other ) return false unless other.instance_of? self.class self.mtime == other.mtime and self.size == other.size end |
#removed? ⇒ Boolean
Is the file represented by this FileStat to be considered removed?
FileStat doesn’t actually go to the file system and check, it assumes if the FileStat was initialized with a nil mtime or a nil size then that data wasn’t available, and therefore must indicate that the file is no longer in existence.
42 43 44 |
# File 'lib/directory_watcher/file_stat.rb', line 42 def removed? @mtime.nil? || @size.nil? end |
#to_s ⇒ Object
Create a nice string based representation of this instance.
62 63 64 |
# File 'lib/directory_watcher/file_stat.rb', line 62 def to_s "<#{self.class.name} path: #{path} mtime: #{mtime} size: #{size}>" end |