Class: Everyx::PeriodicTasks::FileMonitor

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeFileMonitor

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

#fnameObject (readonly)

Returns the value of attribute fname.



51
52
53
# File 'lib/everyx.rb', line 51

def fname
  @fname
end

Instance Method Details

#callObject



68
69
70
71
72
# File 'lib/everyx.rb', line 68

def call
  if check
    NServer::Client.try_notify("File #{@fname} modified.")
  end
end

#checkObject



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