Module: RJSV::Watch

Defined in:
lib/rjsv/watch.rb

Overview

Module for real-time monitoring of files on the local disk. It uses the ‘listen’ library for this function. There is only one method that can be loaded here which triggers everything.

Class Method Summary collapse

Class Method Details

.modified_files(*paths, &block) ⇒ Object

Tracks modified files in the paths that are defined as the source directories. When this function is called, the event listener is triggered for events such as modified, added, and deleted file events. Therefore, the method can put the application to sleep and silently monitor the event process. It watches all files with the extension ‘.*.rb’, where the asterisk means any sub-extension such as ‘.js’.



24
25
26
27
28
29
30
31
32
33
# File 'lib/rjsv/watch.rb', line 24

def modified_files(*paths, &block)
  listener = Listen.to(*paths,
    only: /\..*\.#{Constants::SUFFIX_RB}$/
  ) do |m, a, r|
    
    block.call(m, a, r) if block
  end
  listener.start
  sleep
end