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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileMonitor

Returns a new instance of FileMonitor.



47
48
49
50
# File 'lib/everyx.rb', line 47

def initialize
  @fname = nil
  @mtime = nil
end

Instance Attribute Details

#fnameObject (readonly)

Returns the value of attribute fname.



45
46
47
# File 'lib/everyx.rb', line 45

def fname
  @fname
end

Instance Method Details

#callObject



62
63
64
65
66
# File 'lib/everyx.rb', line 62

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

#checkObject



52
53
54
55
56
57
58
59
60
# File 'lib/everyx.rb', line 52

def check
  new_time = File.mtime(@fname)
  if new_time != @mtime
    @mtime = new_time
    return true
  else
    return false
  end
end