Sha256: 8165105174e0a7515b6488a1463ecbbec4906cc5974c514dc251e8c4aaed7d6d

Contents?: true

Size: 1.35 KB

Versions: 101

Compression:

Stored size: 1.35 KB

Contents

class Knj::Event_filemod
  attr_reader :args
  
  def initialize(args, &block)
    @args = args
    @run = true
    @mutex = Mutex.new
    
    @args[:wait] = 1 if !@args.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?
        
        @mutex.synchronize do
          @args[:paths].each do |path|
            changed = false
            
            if @mtimes and !@mtimes.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
  end
  
  def destroy
    @mtimes = {}
    @run = false
    @args = nil
  end
  
  def add_path(fpath)
    @args[:paths] << fpath
  end
end

Version data entries

101 entries across 101 versions & 1 rubygems

Version Path
knjrbfw-0.0.94 lib/knj/event_filemod.rb
knjrbfw-0.0.93 lib/knj/event_filemod.rb
knjrbfw-0.0.92 lib/knj/event_filemod.rb
knjrbfw-0.0.91 lib/knj/event_filemod.rb
knjrbfw-0.0.90 lib/knj/event_filemod.rb
knjrbfw-0.0.89 lib/knj/event_filemod.rb
knjrbfw-0.0.88 lib/knj/event_filemod.rb
knjrbfw-0.0.87 lib/knj/event_filemod.rb
knjrbfw-0.0.86 lib/knj/event_filemod.rb
knjrbfw-0.0.85 lib/knj/event_filemod.rb
knjrbfw-0.0.84 lib/knj/event_filemod.rb
knjrbfw-0.0.83 lib/knj/event_filemod.rb
knjrbfw-0.0.82 lib/knj/event_filemod.rb
knjrbfw-0.0.81 lib/knj/event_filemod.rb
knjrbfw-0.0.80 lib/knj/event_filemod.rb
knjrbfw-0.0.79 lib/knj/event_filemod.rb
knjrbfw-0.0.78 lib/knj/event_filemod.rb
knjrbfw-0.0.77 lib/knj/event_filemod.rb
knjrbfw-0.0.75 lib/knj/event_filemod.rb
knjrbfw-0.0.74 lib/knj/event_filemod.rb