pax_global_header00006660000000000000000000000064132733436300014516gustar00rootroot0000000000000052 comment=7f73ff7ac3477146e2f561ea1238f39d74954826 ruby-spring-watcher-listen-2.0.1/000077500000000000000000000000001327334363000167265ustar00rootroot00000000000000ruby-spring-watcher-listen-2.0.1/.gitignore000066400000000000000000000003031327334363000207120ustar00rootroot00000000000000*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp *.bundle *.so *.o *.a mkmf.log test/apps ruby-spring-watcher-listen-2.0.1/.travis.yml000066400000000000000000000000361327334363000210360ustar00rootroot00000000000000language: ruby rvm: - 2.3.1 ruby-spring-watcher-listen-2.0.1/Gemfile000066400000000000000000000002201327334363000202130ustar00rootroot00000000000000source 'https://rubygems.org' # Specify your gem's dependencies in spring-watcher-listen.gemspec gemspec gem "spring", github: "rails/spring" ruby-spring-watcher-listen-2.0.1/LICENSE.txt000066400000000000000000000020551327334363000205530ustar00rootroot00000000000000Copyright (c) 2014 Jon Leighton MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ruby-spring-watcher-listen-2.0.1/README.md000066400000000000000000000017121327334363000202060ustar00rootroot00000000000000# Listen watcher for Spring [![Build Status](https://travis-ci.org/jonleighton/spring-watcher-listen.png?branch=master)](https://travis-ci.org/jonleighton/spring-watcher-listen) [![Gem Version](https://badge.fury.io/rb/spring-watcher-listen.png)](http://badge.fury.io/rb/spring-watcher-listen) This gem makes [Spring](https://github.com/rails/spring) watch the filesystem for changes using [Listen](https://github.com/guard/listen) rather than by polling the filesystem. On larger projects this means spring will be more responsive, more accurate and use less cpu on local filesystems. (NFS, shared VM folders and user file systems will still need polling) Listen 2.7 and higher and 3.0 are supported. If you rely on Listen 1 you can use v1.0.0 of this gem. ## Installation Stop Spring if it's already running: $ spring stop Add this line to your application's Gemfile: gem 'spring-watcher-listen', group: :development And then execute: $ bundle ruby-spring-watcher-listen-2.0.1/Rakefile000066400000000000000000000003011327334363000203650ustar00rootroot00000000000000require "bundler/gem_tasks" require "rake/testtask" Rake::TestTask.new(:test) do |t| t.libs << "test" t.test_files = FileList["test/*_test.rb"] t.verbose = true end task default: :test ruby-spring-watcher-listen-2.0.1/lib/000077500000000000000000000000001327334363000174745ustar00rootroot00000000000000ruby-spring-watcher-listen-2.0.1/lib/spring/000077500000000000000000000000001327334363000207765ustar00rootroot00000000000000ruby-spring-watcher-listen-2.0.1/lib/spring/watcher/000077500000000000000000000000001327334363000224335ustar00rootroot00000000000000ruby-spring-watcher-listen-2.0.1/lib/spring/watcher/listen.rb000066400000000000000000000031001327334363000242500ustar00rootroot00000000000000require "spring/watcher" require "spring/watcher/abstract" require "listen" require "listen/version" if defined?(Celluloid) # fork() doesn't preserve threads, so a clean # Celluloid shutdown isn't possible, but we can # reduce the 10 second timeout # There's a patch for Celluloid to avoid this (search for 'fork' in Celluloid # issues) Celluloid.shutdown_timeout = 2 end module Spring module Watcher class Listen < Abstract Spring.watch_method = self attr_reader :listener def start unless @listener @listener = ::Listen.to(*base_directories, latency: latency, &method(:changed)) @listener.start end end def stop if @listener @listener.stop @listener = nil end end def subjects_changed return unless @listener return unless @listener.respond_to?(:directories) return unless @listener.directories.sort != base_directories.sort restart 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.map { |path| Pathname.new(path) } end end end end ruby-spring-watcher-listen-2.0.1/spring-watcher-listen.gemspec000066400000000000000000000015561327334363000245330ustar00rootroot00000000000000# coding: utf-8 Gem::Specification.new do |spec| spec.name = "spring-watcher-listen" spec.version = "2.0.1" spec.authors = ["Jon Leighton"] spec.email = ["j@jonathanleighton.com"] spec.summary = %q{Makes spring watch files using the listen gem.} spec.homepage = "https://github.com/jonleighton/spring-watcher-listen" spec.license = "MIT" spec.files = `git ls-files -z`.split("\x0") spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] spec.add_development_dependency "bundler", "~> 1.6" spec.add_development_dependency "rake" spec.add_development_dependency "activesupport" spec.add_dependency "spring", ">= 1.2", "< 3.0" spec.add_dependency "listen", ">= 2.7", '< 4.0' end ruby-spring-watcher-listen-2.0.1/test/000077500000000000000000000000001327334363000177055ustar00rootroot00000000000000ruby-spring-watcher-listen-2.0.1/test/acceptance_test.rb000066400000000000000000000010621327334363000233560ustar00rootroot00000000000000require "helper" class AcceptanceTest < Spring::Test::AcceptanceTest class ApplicationGenerator < Spring::Test::ApplicationGenerator def generate_files super File.write(application.gemfile, "#{application.gemfile.read}gem 'spring-watcher-listen'\n") end def manually_built_gems super + %w(spring-watcher-listen) end end def generator_klass ApplicationGenerator end test "uses the listen watcher" do assert_success "bin/rails runner 'puts Spring.watcher.class'", stdout: "Spring::Watcher::Listen" end end ruby-spring-watcher-listen-2.0.1/test/helper.rb000066400000000000000000000004321327334363000215100ustar00rootroot00000000000000$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) require "bundler/setup" require "spring/test" require "minitest/autorun" if defined?(Celluloid) require "celluloid/test" Celluloid.logger.level = Logger::WARN end Spring::Test.root = File.expand_path('..', __FILE__) ruby-spring-watcher-listen-2.0.1/test/unit_test.rb000066400000000000000000000030131327334363000222450ustar00rootroot00000000000000require "helper" require "spring/test/watcher_test" require "spring/watcher/listen" class ListenWatcherTest < Spring::Test::WatcherTest def watcher_class Spring::Watcher::Listen end setup do Celluloid.boot if defined?(Celluloid) end teardown { Listen.stop } test "root directories" do begin other_dir_1 = File.realpath(Dir.mktmpdir) other_dir_2 = File.realpath(Dir.mktmpdir) File.write("#{other_dir_1}/foo", "foo") File.write("#{dir}/foo", "foo") watcher.add "#{other_dir_1}/foo" watcher.add other_dir_2 watcher.add "#{dir}/foo" dirs = [dir, other_dir_1, other_dir_2].sort.map { |path| Pathname.new(path) } assert_equal dirs, watcher.base_directories.sort ensure FileUtils.rmdir other_dir_1 FileUtils.rmdir other_dir_2 end end test "root directories with a root subpath directory" do begin other_dir_1 = "#{dir}_other" other_dir_2 = "#{dir}_core" # same subpath as dir but with _other or _core appended FileUtils::mkdir_p(other_dir_1) FileUtils::mkdir_p(other_dir_2) File.write("#{other_dir_1}/foo", "foo") File.write("#{other_dir_2}/foo", "foo") File.write("#{dir}/foo", "foo") watcher.add "#{other_dir_1}/foo" watcher.add other_dir_2 dirs = [dir, other_dir_1, other_dir_2].sort.map { |path| Pathname.new(path) } assert_equal dirs, watcher.base_directories.sort ensure FileUtils.rmdir other_dir_1 FileUtils.rmdir other_dir_2 end end end