class DirectoryWatcher::Event
An Event
structure contains the type of the event and
the file path to which the event pertains. The type can be one of
the following:
:added => file has been added to the directory :modified => file has been modified (either mtime or size or both have changed) :removed => file has been removed from the directory :stable => file has stabilized since being added or modified
Attributes
path[R]
stat[R]
type[R]
Public Class Methods
from_stats( old_stat, new_stat )
click to toggle source
Create one of the 4 types of events given the two stats
The rules are:
:added => old_stat will be nil and new_stat will exist :removed => old_stat will exist and new_stat will be nil :modified => old_stat != new_stat :stable => old_stat == new_stat and
# File lib/directory_watcher/event.rb, line 25 def self.from_stats( old_stat, new_stat ) if old_stat != new_stat then return DirectoryWatcher::Event.new( :removed, new_stat.path ) if new_stat.removed? return DirectoryWatcher::Event.new( :added, new_stat.path, new_stat ) if old_stat.nil? return DirectoryWatcher::Event.new( :modified, new_stat.path, new_stat ) else return DirectoryWatcher::Event.new( :stable, new_stat.path, new_stat ) end end
new( type, path, stat = nil )
click to toggle source
Create a new Event with one of the 4 types and the path of the file.
# File lib/directory_watcher/event.rb, line 37 def initialize( type, path, stat = nil ) @type = type @path = path @stat = stat end
Public Instance Methods
added?()
click to toggle source
Is the event an added event.
# File lib/directory_watcher/event.rb, line 51 def added? type == :added end
modified?()
click to toggle source
Is the event a modified event.
# File lib/directory_watcher/event.rb, line 45 def modified? type == :modified end
removed?()
click to toggle source
Is the event a removed event.
# File lib/directory_watcher/event.rb, line 57 def removed? type == :removed end
stable?()
click to toggle source
Is the event a stable event.
# File lib/directory_watcher/event.rb, line 63 def stable? type == :stable end
to_s( )
click to toggle source
Convert the Event to a nice string format
# File lib/directory_watcher/event.rb, line 69 def to_s( ) "<#{self.class} type: #{type} path: '#{path}'>" end