Class: Everyx::PeriodicTasks::FileMonitor
- Inherits:
-
Object
- Object
- Everyx::PeriodicTasks::FileMonitor
- Defined in:
- lib/everyx.rb
Overview
This class will monitor a file, and create an NServer message when every the file modification time changes.
You’ll have to set the fname
for the file.
Example:
fm = Everyx::PeriodicTasks::FileMonitor.new
fm.fname = '/tmp/file.txt'
Instance Attribute Summary collapse
-
#fname ⇒ Object
readonly
Returns the value of attribute fname.
Instance Method Summary collapse
- #call ⇒ Object
- #check ⇒ Object
-
#initialize ⇒ FileMonitor
constructor
A new instance of FileMonitor.
Constructor Details
#initialize ⇒ FileMonitor
Returns a new instance of FileMonitor.
53 54 55 56 |
# File 'lib/everyx.rb', line 53 def initialize @fname = nil @mtime = nil end |
Instance Attribute Details
#fname ⇒ Object (readonly)
Returns the value of attribute fname.
51 52 53 |
# File 'lib/everyx.rb', line 51 def fname @fname end |
Instance Method Details
#call ⇒ Object
68 69 70 71 72 |
# File 'lib/everyx.rb', line 68 def call if check NServer::Client.try_notify("File #{@fname} modified.") end end |
#check ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/everyx.rb', line 58 def check new_time = File.mtime(@fname) if new_time != @mtime @mtime = new_time return true else return false end end |