Module: Watchr::EventHandler::EM::SingleFileWatcher
- Defined in:
- lib/watchr/event_handlers/em.rb
Overview
:nodoc:
Class Attribute Summary collapse
-
.handler ⇒ Object
Stores a reference back to handler so we can call its #nofity method with file event info.
Instance Method Summary collapse
- #file_deleted ⇒ Object
- #file_modified ⇒ Object
- #file_moved ⇒ Object
- #init(first_time, event) ⇒ Object
-
#pathname ⇒ Object
File’s path as a Pathname.
- #stop ⇒ Object
Class Attribute Details
.handler ⇒ Object
Stores a reference back to handler so we can call its #nofity method with file event info
25 26 27 |
# File 'lib/watchr/event_handlers/em.rb', line 25 def handler @handler end |
Instance Method Details
#file_deleted ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/watchr/event_handlers/em.rb', line 61 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_modified ⇒ Object
43 44 45 46 47 |
# File 'lib/watchr/event_handlers/em.rb', line 43 def file_modified # p "mod", pathname, type SingleFileWatcher.handler.notify(pathname, type) update_reference_times end |
#file_moved ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/watchr/event_handlers/em.rb', line 49 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
28 29 30 31 32 33 34 35 36 |
# File 'lib/watchr/event_handlers/em.rb', line 28 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 |
#pathname ⇒ Object
File’s path as a Pathname
39 40 41 |
# File 'lib/watchr/event_handlers/em.rb', line 39 def pathname @pathname ||= Pathname(path) end |
#stop ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/watchr/event_handlers/em.rb', line 75 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 |