spring-watcher-listen 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8fa26b896b479001b9aae68a5d14ecc0812791f0
4
+ data.tar.gz: 5b63d1853eb63117b8cac9deedfc9359138f367a
5
+ SHA512:
6
+ metadata.gz: ced8ae4e65b28c9c9a19fc414402dfda9d0a5c20e9216f40a008fa1146269f55d3fc86c4676b9065f92f9b7f2c4d8617159dc43ebaeaea66526f6b9c6043907c
7
+ data.tar.gz: e3f21954701269628b287880700ceb4e5ebb9b426f6cbe0ce84dd9f46572f728a9596d6a65e1c5ee28ebc3c4d41ceb06a9f2aa209b82cf28c676d1f1f5e699af
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ test/apps
data/.travis.yml ADDED
@@ -0,0 +1 @@
1
+ language: ruby
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in spring-watcher-listen.gemspec
4
+ gemspec
5
+
6
+ gem "spring", github: "rails/spring"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jon Leighton
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # Listen watcher for Spring
2
+
3
+ [![Build Status](https://travis-ci.org/jonleighton/spring-watcher-listen.png?branch=master)](https://travis-ci.org/jonleighton/spring-watcher-listen)
4
+ [![Gem Version](https://badge.fury.io/rb/spring-watcher-listen.png)](http://badge.fury.io/rb/spring-watcher-listen)
5
+
6
+ This gem makes [Spring](https://github.com/rails/spring) watch the
7
+ filesystem for changes using [Listen](https://github.com/guard/listen)
8
+ rather than by polling the filesystem.
9
+
10
+ Currently only Listen 1 is supported. However there is [an
11
+ effort](https://github.com/jonleighton/spring-watcher-listen/issues/1)
12
+ to implement Listen 2 support.
13
+
14
+ ## Installation
15
+
16
+ Stop Spring if it's already running:
17
+
18
+ $ spring stop
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ gem 'spring-watcher-listen', group: :development
23
+
24
+ And then execute:
25
+
26
+ $ bundle
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList["test/*_test.rb"]
7
+ t.verbose = true
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,56 @@
1
+ require "spring/watcher"
2
+ require "spring/watcher/abstract"
3
+
4
+ require "listen"
5
+ require "listen/version"
6
+
7
+ module Spring
8
+ module Watcher
9
+ class Listen < Abstract
10
+ Spring.watch_method = self
11
+
12
+ attr_reader :listener
13
+
14
+ def start
15
+ unless @listener
16
+ @listener = ::Listen.to(*base_directories, relative_paths: false)
17
+ @listener.latency(latency)
18
+ @listener.change(&method(:changed))
19
+ @listener.start
20
+ end
21
+ end
22
+
23
+ def stop
24
+ if @listener
25
+ @listener.stop
26
+ @listener = nil
27
+ end
28
+ end
29
+
30
+ def subjects_changed
31
+ if @listener && @listener.directories.sort != base_directories.sort
32
+ restart
33
+ end
34
+ end
35
+
36
+ def watching?(file)
37
+ files.include?(file) || file.start_with?(*directories)
38
+ end
39
+
40
+ def changed(modified, added, removed)
41
+ synchronize do
42
+ if (modified + added + removed).any? { |f| watching? f }
43
+ mark_stale
44
+ end
45
+ end
46
+ end
47
+
48
+ def base_directories
49
+ ([root] +
50
+ files.reject { |f| f.start_with? "#{root}/" }.map { |f| File.expand_path("#{f}/..") } +
51
+ directories.reject { |d| d.start_with? "#{root}/" }
52
+ ).uniq
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "spring-watcher-listen"
5
+ spec.version = "1.0.0"
6
+ spec.authors = ["Jon Leighton"]
7
+ spec.email = ["j@jonathanleighton.com"]
8
+ spec.summary = %q{Makes spring watch files using the listen gem.}
9
+ spec.homepage = "https://github.com/jonleighton/spring-watcher-listen"
10
+ spec.license = "MIT"
11
+
12
+ spec.files = `git ls-files -z`.split("\x0")
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_development_dependency "bundler", "~> 1.6"
18
+ spec.add_development_dependency "rake"
19
+ spec.add_development_dependency "activesupport"
20
+
21
+ spec.add_dependency "spring", "~> 1.2"
22
+ spec.add_dependency "listen", "~> 1.0"
23
+ end
@@ -0,0 +1,22 @@
1
+ require "helper"
2
+
3
+ class AcceptanceTest < Spring::Test::AcceptanceTest
4
+ class ApplicationGenerator < Spring::Test::ApplicationGenerator
5
+ def generate_files
6
+ super
7
+ File.write(application.gemfile, "#{application.gemfile.read}gem 'spring-watcher-listen'\n")
8
+ end
9
+
10
+ def manually_built_gems
11
+ super + %w(spring-watcher-listen)
12
+ end
13
+ end
14
+
15
+ def generator_klass
16
+ ApplicationGenerator
17
+ end
18
+
19
+ test "uses the listen watcher" do
20
+ assert_success "bin/rails runner 'puts Spring.watcher.class'", stdout: "Spring::Watcher::Listen"
21
+ end
22
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+
3
+ require "bundler/setup"
4
+ require "spring/test"
5
+ require "minitest/autorun"
6
+
7
+ Spring::Test.root = File.expand_path('..', __FILE__)
data/test/unit_test.rb ADDED
@@ -0,0 +1,48 @@
1
+ require "helper"
2
+ require "spring/test/watcher_test"
3
+ require "spring/watcher/listen"
4
+
5
+ class ListenWatcherTest < Spring::Test::WatcherTest
6
+ def watcher_class
7
+ Spring::Watcher::Listen
8
+ end
9
+
10
+ test "root directories" do
11
+ begin
12
+ other_dir_1 = File.realpath(Dir.mktmpdir)
13
+ other_dir_2 = File.realpath(Dir.mktmpdir)
14
+ File.write("#{other_dir_1}/foo", "foo")
15
+ File.write("#{dir}/foo", "foo")
16
+
17
+ watcher.add "#{other_dir_1}/foo"
18
+ watcher.add other_dir_2
19
+ watcher.add "#{dir}/foo"
20
+
21
+ assert_equal [dir, other_dir_1, other_dir_2].sort, watcher.base_directories.sort
22
+ ensure
23
+ FileUtils.rmdir other_dir_1
24
+ FileUtils.rmdir other_dir_2
25
+ end
26
+ end
27
+
28
+ test "root directories with a root subpath directory" do
29
+ begin
30
+ other_dir_1 = "#{dir}_other"
31
+ other_dir_2 = "#{dir}_core"
32
+ # same subpath as dir but with _other or _core appended
33
+ FileUtils::mkdir_p(other_dir_1)
34
+ FileUtils::mkdir_p(other_dir_2)
35
+ File.write("#{other_dir_1}/foo", "foo")
36
+ File.write("#{other_dir_2}/foo", "foo")
37
+ File.write("#{dir}/foo", "foo")
38
+
39
+ watcher.add "#{other_dir_1}/foo"
40
+ watcher.add other_dir_2
41
+
42
+ assert_equal [dir, other_dir_1, other_dir_2].sort, watcher.base_directories.sort
43
+ ensure
44
+ FileUtils.rmdir other_dir_1
45
+ FileUtils.rmdir other_dir_2
46
+ end
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spring-watcher-listen
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jon Leighton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: spring
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: listen
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ description:
84
+ email:
85
+ - j@jonathanleighton.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/spring/watcher/listen.rb
97
+ - spring-watcher-listen.gemspec
98
+ - test/acceptance_test.rb
99
+ - test/helper.rb
100
+ - test/unit_test.rb
101
+ homepage: https://github.com/jonleighton/spring-watcher-listen
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Makes spring watch files using the listen gem.
125
+ test_files:
126
+ - test/acceptance_test.rb
127
+ - test/helper.rb
128
+ - test/unit_test.rb