Sha256: 0f6c4f78b16a7cbc3905a2de2fc7e37017f7634d3ed40209966b8ccee7162535

Contents?: true

Size: 646 Bytes

Versions: 5

Compression:

Stored size: 646 Bytes

Contents

module Guard
  class Polling < Listener
    attr_reader :callback, :latency

    def initialize
      super
      @latency = 1.5
    end

    def on_change(&callback)
      @callback = callback
    end

    def start
      @stop = false
      watch_change
    end

    def stop
      @stop = true
    end

  private

    def watch_change
      while !@stop
        start = Time.now.to_f
        files = modified_files([Dir.pwd + '/'], :all => true)
        update_last_event
        callback.call(files) unless files.empty?
        nap_time = latency - (Time.now.to_f - start)
        sleep(nap_time) if nap_time > 0
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
guard-0.3.4 lib/guard/listeners/polling.rb
guard-0.3.3 lib/guard/listeners/polling.rb
guard-0.3.2 lib/guard/listeners/polling.rb
guard-0.3.1 lib/guard/listeners/polling.rb
guard-0.3.0 lib/guard/listeners/polling.rb