Module: Wake::EventHandler::EM::SingleFileWatcher

Defined in:
lib/wake/event_handlers/em.rb

Overview

:nodoc:

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.handlerObject

Stores a reference back to handler so we can call its #nofity method with file event info



26
27
28
# File 'lib/wake/event_handlers/em.rb', line 26

def handler
  @handler
end

Instance Method Details

#file_deletedObject



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/wake/event_handlers/em.rb', line 62

def file_deleted
  # p "del", pathname
  # $stderr.puts "stop.fd #{signature}: #{pathname} #{type}"
  SingleFileWatcher.handler.forget self, pathname
  SingleFileWatcher.handler.notify(pathname, :deleted)
  if type == :modified
    # There's a race condition here ... the directory should have gotten mod'ed, but we'll get the
    # delete after the directory scan, so we won't watch the new file. This isn't the cleanest way to
    # handle this, but should work for now ...
    SingleFileWatcher.handler.watch pathname
  else
  end
end

#file_modifiedObject



44
45
46
47
48
# File 'lib/wake/event_handlers/em.rb', line 44

def file_modified
  # p "mod", pathname, type
  SingleFileWatcher.handler.notify(pathname, type)
  update_reference_times
end

#file_movedObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/wake/event_handlers/em.rb', line 50

def file_moved
  # p "mov", pathname
  SingleFileWatcher.handler.forget self, pathname
  begin
    # $stderr.puts "stop.fm #{signature}: #{pathname}"
    stop_watching
  rescue Exception => e
    $stderr.puts "exception while attempting to stop_watching in file_moved: #{e}"
  end
  SingleFileWatcher.handler.notify(pathname, type)
end

#init(first_time, event) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/wake/event_handlers/em.rb', line 29

def init first_time, event
  # p "w", path, first_time,(first_time ? :load : :created)
  # $stderr.puts "#{signature}: #{pathname}"
  update_reference_times
  # FIX: doesn't pass events
  if !event
    SingleFileWatcher.handler.notify(pathname, (first_time ? :load : :created) )
  end
end

#pathnameObject

File’s path as a Pathname



40
41
42
# File 'lib/wake/event_handlers/em.rb', line 40

def pathname
  @pathname ||= Pathname(path)
end

#stopObject



76
77
78
79
80
81
82
83
84
# File 'lib/wake/event_handlers/em.rb', line 76

def stop
  #  p "stop", pathname
  begin
    # $stderr.puts "stop.s #{signature}: #{pathname}"
    stop_watching
  rescue Exception => e
    $stderr.puts "exception while attempting to stop_watching in stop: #{e}"
  end
end