Sha256: a376ac9805617fa8ea2610f644e8fa5377af12a0b9ab4dbd1eb149876a8c6d31
Contents?: true
Size: 1.02 KB
Versions: 2
Compression:
Stored size: 1.02 KB
Contents
class Knj::Event_filemod attr_reader :args def initialize(args, &block) @args = args @run = true @args[:wait] = 1 if !@args.has_key?(:wait) @mtimes = {} args[:paths].each do |path| @mtimes[path] = File.mtime(path) end Knj::Thread.new do while @run do break if !@args or !@args[:paths] or @args[:paths].empty? @args[:paths].clone.each do |path| changed = false if @mtimes and !@mtimes.has_key?(path) and @mtimes.is_a?(Hash) @mtimes[path] = File.mtime(path) end begin newdate = File.mtime(path) rescue Errno::ENOENT #file does not exist. changed = true end if !changed and newdate and @mtimes and newdate > @mtimes[path] changed = true end if changed block.call(self, path) @args[:paths].delete(path) if @args and @args[:break_when_changed] end end sleep @args[:wait] if @args and @run end end end def destroy @mtimes = {} @run = false @args = nil end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
knjrbfw-0.0.4 | lib/knj/event_filemod.rb |
knjrbfw-0.0.3 | lib/knj/event_filemod.rb |