Class: EventMachine::FileWatch

Inherits:
Connection show all
Defined in:
lib/em/file_watch.rb

Overview

This is subclassed from EventMachine::Connection for use with the file monitoring API. Read the documentation on the instance methods of this class, and for a full explanation see EventMachine.watch_file.

Constant Summary collapse

Cmodified =

:stopdoc:

'modified'.freeze
Cdeleted =
'deleted'.freeze
Cmoved =
'moved'.freeze

Instance Attribute Summary

Attributes inherited from Connection

#signature

Instance Method Summary collapse

Methods inherited from Connection

#associate_callback_target, #close_connection, #close_connection_after_writing, #comm_inactivity_timeout, #comm_inactivity_timeout=, #connection_completed, #detach, #error?, #get_outbound_data_size, #get_peer_cert, #get_peername, #get_pid, #get_sock_opt, #get_sockname, #get_status, #initialize, new, #notify_readable=, #notify_readable?, #notify_writable=, #notify_writable?, #pause, #paused?, #pending_connect_timeout, #pending_connect_timeout=, #post_init, #proxy_incoming_to, #proxy_target_unbound, #reconnect, #resume, #send_data, #send_datagram, #send_file_data, #set_comm_inactivity_timeout, #set_pending_connect_timeout, #ssl_handshake_completed, #ssl_verify_peer, #start_tls, #stop_proxying, #stream_file_data, #unbind

Constructor Details

This class inherits a constructor from EventMachine::Connection

Instance Method Details

#file_deletedObject

Should be redefined with the user’s custom callback that will be fired when the file is deleted. When the file is deleted, stop_watching will be called after this to make sure everything is cleaned up correctly.

Note that on linux (with inotify), file_deleted will not be called until all open file descriptors to the file have been closed.



39
40
# File 'lib/em/file_watch.rb', line 39

def file_deleted
end

#file_modifiedObject

Should be redefined with the user’s custom callback that will be fired when the file is modified.



30
31
# File 'lib/em/file_watch.rb', line 30

def file_modified
end

#file_movedObject

Should be redefined with the user’s custom callback that will be fired when the file is moved or renamed.



43
44
# File 'lib/em/file_watch.rb', line 43

def file_moved
end

#pathObject

Returns the path that EventMachine::watch_file was originally called with. The current implementation does not pick up on the new filename after a rename occurs.



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

def path
  @path
end

#receive_data(data) ⇒ Object

:startdoc:



12
13
14
15
16
17
18
19
20
21
# File 'lib/em/file_watch.rb', line 12

def receive_data(data) #:nodoc:
  case data
  when Cmodified
    file_modified
  when Cdeleted
    file_deleted
  when Cmoved
    file_moved
  end
end

#stop_watchingObject

Discontinue monitoring of the file. This involves cleaning up the underlying monitoring details with kqueue/inotify, and in turn firing unbind. This will be called automatically when a file is deleted. User code may call it as well.



49
50
51
# File 'lib/em/file_watch.rb', line 49

def stop_watching
  EventMachine::unwatch_filename(@signature)
end