Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add listen 2 support. #3

Merged
merged 1 commit into from
Jun 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/spring/watcher/listen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
require "listen"
require "listen/version"

# fork() doesn't preserve threads, so a clean
# Celluloid shutdown isn't possible, but we can
# reduce the 10 second timeout
Celluloid.shutdown_timeout = 2

module Spring
module Watcher
class Listen < Abstract
Expand All @@ -13,9 +18,7 @@ class Listen < Abstract

def start
unless @listener
@listener = ::Listen.to(*base_directories, relative_paths: false)
@listener.latency(latency)
@listener.change(&method(:changed))
@listener = ::Listen.to(*base_directories, latency: latency, &method(:changed))
@listener.start
end
end
Expand Down Expand Up @@ -49,7 +52,7 @@ 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
).uniq.map { |path| Pathname.new(path) }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spring-watcher-listen.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "activesupport"

spec.add_dependency "spring", "~> 1.2"
spec.add_dependency "listen", "~> 1.0"
spec.add_dependency "listen", "~> 2.7"
end
3 changes: 3 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
require "spring/test"
require "minitest/autorun"

require "celluloid/test"
Celluloid.logger.level = Logger::WARN

Spring::Test.root = File.expand_path('..', __FILE__)
12 changes: 10 additions & 2 deletions test/unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ def watcher_class
Spring::Watcher::Listen
end

setup {
Celluloid.boot
}

teardown { Listen.stop }

test "root directories" do
begin
other_dir_1 = File.realpath(Dir.mktmpdir)
Expand All @@ -18,7 +24,8 @@ def watcher_class
watcher.add other_dir_2
watcher.add "#{dir}/foo"

assert_equal [dir, other_dir_1, other_dir_2].sort, watcher.base_directories.sort
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
Expand All @@ -39,7 +46,8 @@ def watcher_class
watcher.add "#{other_dir_1}/foo"
watcher.add other_dir_2

assert_equal [dir, other_dir_1, other_dir_2].sort, watcher.base_directories.sort
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
Expand Down