filesystems - How to monitor individual files with Ruby listen gem? -


i'm trying use listen gem (https://github.com/guard/listen) listen specific files, far have been able base functionality of listening whole directories working properly.

here's example of i'm trying @ moment:

require "listen"  module filetracker   filedir = "/home/user/dir"   filenames = [ "file1", "file2" ]    # should track 'file1' , 'file2' in directory   listener = listen.to(filedir, only: filenames) |modified, added, removed|     puts "updated: " + modified.first   end    listener.start   sleep end 

i have tried specifying single filename string only: parameter, didn't work either.

my end goal able track list of user-defined files in various directories changes. want track each specific file, not the entire directory.

i wasn't paying attention doing here. only: takes regex, failing construct , provide. can else out may need use listen watch or ignore specific files.

here example of working solution:

module filetracker   filedir = "/home/user/dir"   filenames = [ "file1", "file2" ]    listenregex = filenames.join("$|").gsub!(".", "\.") + "$"    # should track 'file1' , 'file2' in directory   listener = listen.to(filedir, only: /#{listenregex}/) |modified, added, removed|     puts "updated: " + modified.first   end    listener.start   sleep end 

Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -