class FileWatcher
Public Class Methods
new(path)
click to toggle source
# File lib/file_watcher.rb, line 4 def initialize(path) @path = path @listener = nil end
Public Instance Methods
onlyReg()
click to toggle source
# File lib/file_watcher.rb, line 29 def onlyReg /\.m$/ end
startWatcher() { |modified| ... }
click to toggle source
# File lib/file_watcher.rb, line 9 def startWatcher if File.directory?(@path) == false @path = File.dirname(@path) if File.directory?(@path) puts "watcher path not exist: #{@path}" return end end @listener = Listen.to(@path, only: onlyReg) do |modified, added, removed| modified.each { |path| path.force_encoding('utf-8') } yield(modified) unless modified.empty? # added.each { |path| path.force_encoding('utf-8') } # removed.each { |path| path.force_encoding('utf-8') } end @listener.start sleep end