Sha256: ffc2f4c30eea190488144d0ae6d42247f61a94e6481801f92fcaf26b960efbc3

Contents?: true

Size: 1.17 KB

Versions: 14

Compression:

Stored size: 1.17 KB

Contents

gem "listen", "~> 1.0"
require "listen"
require "listen/version"

module Spring
  module Watcher
    class Listen < Abstract
      attr_reader :listener

      def start
        unless @listener
          @listener = ::Listen.to(*base_directories, relative_paths: false)
          @listener.latency(latency)
          @listener.change(&method(:changed))
          @listener.start
        end
      end

      def stop
        if @listener
          @listener.stop
          @listener = nil
        end
      end

      def subjects_changed
        if @listener && @listener.directories.sort != base_directories.sort
          restart
        end
      end

      def watching?(file)
        files.include?(file) || file.start_with?(*directories)
      end

      def changed(modified, added, removed)
        synchronize do
          if (modified + added + removed).any? { |f| watching? f }
            mark_stale
          end
        end
      end

      def base_directories
        ([root] +
          files.reject       { |f| f.start_with? root }.map { |f| File.expand_path("#{f}/..") } +
          directories.reject { |d| d.start_with? root }
        ).uniq
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
spring-1.1.3 lib/spring/watcher/listen.rb
spring-1.1.2 lib/spring/watcher/listen.rb
spring-1.1.1 lib/spring/watcher/listen.rb
spring-1.1.0 lib/spring/watcher/listen.rb
spring-1.1.0.beta4 lib/spring/watcher/listen.rb
spring-1.1.0.beta3 lib/spring/watcher/listen.rb
spring-1.1.0.beta2 lib/spring/watcher/listen.rb
spring-1.1.0.beta1 lib/spring/watcher/listen.rb
spring-1.0.0 lib/spring/watcher/listen.rb
spring-0.9.2 lib/spring/watcher/listen.rb
spring-0.9.1 lib/spring/watcher/listen.rb
spring-0.9.0 lib/spring/watcher/listen.rb
spring-0.0.11 lib/spring/watcher/listen.rb
spring-0.0.10 lib/spring/watcher/listen.rb