Module: Watchr::EventHandler::EM::SingleFileWatcher

Defined in:
lib/watchr/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



25
26
27
# File 'lib/watchr/event_handlers/em.rb', line 25

def handler
  @handler
end

Instance Method Details

#file_deletedObject



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_modifiedObject



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_movedObject



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

#pathnameObject

File’s path as a Pathname



39
40
41
# File 'lib/watchr/event_handlers/em.rb', line 39

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

#stopObject



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