WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 457c3cb

Browse files
committed
Merge pull request #318 from guard/listen_3x_proposal
Listen 3x proposal
2 parents 9ee289f + 0696aa0 commit 457c3cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2733
-2277
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
language: ruby
22
bundler_args: --without development
33
rvm:
4-
- 1.9.3
5-
- 2.2.0
4+
- 2.2.2
65
- jruby
76
- rbx-2
87
matrix:
@@ -18,5 +17,5 @@ os:
1817
- linux
1918
- osx
2019
env:
21-
- LISTEN_TESTS_DEFAULT_LAG=0.8 LISTEN_TESTS_DEFAULT_TCP_LAG=1.2
20+
- LISTEN_TESTS_DEFAULT_LAG=0.8
2221
sudo: false

Gemfile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
source 'https://rubygems.org'
22

3-
gemspec development_group: :gem_build_tools
3+
# Create this file to use pristine/installed version of Listen for development
4+
use_installed = "./use_installed_guard"
5+
if File.exist?(use_installed)
6+
STDERR.puts "WARNING: using installed version of Listen for development" \
7+
" (remove #{use_installed} file to use local version)"
8+
else
9+
gemspec development_group: :gem_build_tools
10+
end
411

512
require 'rbconfig'
613

714
case RbConfig::CONFIG['target_os']
815
when /mswin|mingw|cygwin/i
916
gem 'wdm', '>= 0.1.0'
10-
Kernel.warn 'NOTE: Celluloid may not work properly on your platform'
1117
when /bsd|dragonfly/i
1218
gem 'rb-kqueue', '>= 0.2'
1319
end
1420

1521
group :test do
16-
gem 'celluloid', github: 'celluloid/celluloid', branch: '0-16-stable'
17-
gem 'celluloid-io', '>= 0.15.0'
1822
gem 'rake'
19-
gem 'rspec', '~> 3.2'
20-
gem 'rspec-retry'
23+
gem 'rspec', '~> 3.3'
2124
gem 'coveralls'
2225
end
2326

Guardfile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
ignore(%r{spec/\.fixtures/})
22

33
group :specs, halt_on_fail: true do
4-
guard :rspec, cmd: 'bundle exec rspec', failed_mode: :keep do
5-
watch(%r{^spec/.+_spec\.rb$})
4+
guard :rspec, cmd: 'bundle exec rspec -t ~acceptance', failed_mode: :keep, all_after_pass: true do
5+
watch(%r{^spec/lib/.+_spec\.rb$})
66
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
77
watch(%r{^spec/support/*}) { 'spec' }
88
watch('spec/spec_helper.rb') { 'spec' }
@@ -13,4 +13,14 @@ group :specs, halt_on_fail: true do
1313
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
1414
watch(%r{(?:.+/)?\.rubocop_todo\.yml$}) { |m| File.dirname(m[0]) }
1515
end
16+
17+
# TODO: guard rspec should have a configurable file for this to work
18+
# TODO: also split up Rakefile
19+
guard :rspec, cmd: 'bundle exec rspec -t acceptance', failed_mode: :keep, all_after_pass: true do
20+
watch(%r{^spec/lib/.+_spec\.rb$})
21+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
22+
watch(%r{^spec/support/*}) { 'spec' }
23+
watch('spec/spec_helper.rb') { 'spec' }
24+
watch(%r{^spec/acceptance/.+_spec\.rb$})
25+
end
1626
end

README.md

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Make sure you know these few basic tricks: https://github.com/guard/listen/wiki/
2020
* Detects file modification, addition and removal.
2121
* You can watch multiple directories.
2222
* Regexp-patterns for ignoring paths for more accuracy and speed
23-
* Forwarding file events over TCP, [more info](#forwarding-file-events-over-tcp) below.
2423
* Increased change detection accuracy on OS X HFS and VFAT volumes.
2524
* Tested on MRI Ruby environments (1.9+ only) via [Travis CI](https://travis-ci.org/guard/listen),
2625

@@ -29,6 +28,8 @@ Please note that:
2928
- Specs suite on JRuby and Rubinius aren't reliable on Travis CI, but should work.
3029
- Windows and \*BSD adapter aren't continuously and automaticaly tested.
3130

31+
NOTE: TCP functionality has been moved to a separate gem (listen-server and listen-client)
32+
3233
## Pending features / issues
3334

3435
* symlinked directories aren't fully transparent yet: https://github.com/guard/listen/issues/279
@@ -166,7 +167,7 @@ force_polling: true # Force the use of the polling a
166167
relative: false # Whether changes should be relative to current dir or not
167168
# default: false
168169

169-
debug: true # Enable Celluloid logger
170+
debug: true # Enable Listen logger
170171
# default: false
171172

172173
polling_fallback_message: 'custom message' # Set a custom polling fallback message (or disable it with false)
@@ -247,47 +248,6 @@ Also, if the directories you're watching contain many files, make sure you're:
247248

248249
When in doubt, LISTEN_GEM_DEBUGGING=2 can help discover the actual events and time they happened.
249250

250-
## Forwarding file events over TCP
251-
252-
Listen is capable of forwarding file events over the network using a messaging protocol. This can be useful for virtualized development environments when file events are unavailable, as is the case with shared folders in VMs.
253-
254-
[Vagrant](https://github.com/mitchellh/vagrant) uses Listen in it's rsync-auto mode to solve this issue.
255-
256-
To broadcast events over TCP programmatically, use the `forward_to` option with an address - just a port or a hostname/port combination:
257-
258-
```ruby
259-
listener = Listen.to 'path/to/app', forward_to: '10.0.0.2:4000' do |modified, added, removed|
260-
# After broadcasting the changes to any connected recipients,
261-
# this block will still be called
262-
end
263-
listener.start
264-
sleep
265-
```
266-
267-
As a convenience, the `listen` script is supplied which listens to a directory and forwards the events to a network address
268-
269-
```bash
270-
listen -f "10.0.0.2:4000" # changes in current directory are sent as absolute paths
271-
listen -r -f "10.0.0.2:4000" # changes in current directory are sent as relative paths
272-
listen -v -d "/projects/my_project" -f "10.0.0.2:4000" # changes in given directory are also shown
273-
```
274-
275-
*NOTE: if you are using a gem like `guard` and the paths on host and guest are not exactly the same, you'll generally want to use the `-r` option for relative paths*
276-
277-
To connect to a broadcasting listener as a recipient, specify its address using `Listen.on`:
278-
279-
```ruby
280-
listener = Listen.on '10.0.0.2:4000' do |modified, added, removed|
281-
# This block will be called
282-
end
283-
listener.start
284-
sleep
285-
```
286-
287-
### Security considerations
288-
289-
Since file events potentially expose sensitive information, care must be taken when specifying the broadcaster address. It is recommended to **always** specify a hostname and make sure it is as specific as possible to reduce any undesirable eavesdropping.
290-
291251
## Development
292252

293253
* Documentation hosted at [RubyDoc](http://rubydoc.info/github/guard/listen/master/frames).

lib/listen.rb

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
require 'celluloid'
1+
require 'logger'
2+
require 'listen/logger'
23
require 'listen/listener'
34

45
require 'listen/internals/thread_pool'
56

7+
# Always set up logging by default first time file is required
8+
#
9+
# NOTE: If you need to clear the logger completely, do so *after*
10+
# requiring this file. If you need to set a custom logger,
11+
# require the listen/logger file and set the logger before requiring
12+
# this file.
13+
Listen.setup_default_logger_if_unset
14+
15+
# Won't print anything by default because of level - unless you've set
16+
# LISTEN_GEM_DEBUGGING or provided your own logger with a high enough level
17+
Listen::Logger.info "Listen loglevel set to: #{Listen.logger.level}"
18+
Listen::Logger.info "Listen version: #{Listen::VERSION}"
19+
620
module Listen
721
class << self
822
# Listens to file system modifications on a either single directory or
923
# multiple directories.
1024
#
11-
# When :forward_to is specified, this listener will broadcast modifications
12-
# over TCP.
13-
#
1425
# @param (see Listen::Listener#new)
1526
#
1627
# @yield [modified, added, removed] the changed files
@@ -21,18 +32,12 @@ class << self
2132
# @return [Listen::Listener] the listener
2233
#
2334
def to(*args, &block)
24-
Celluloid.boot unless Celluloid.running?
25-
options = args.last.is_a?(Hash) ? args.last : {}
26-
target = options.delete(:forward_to)
27-
args = ([target, :broadcaster] + args) if target
28-
_add_listener(*args, &block)
35+
@listeners ||= []
36+
Listener.new(*args, &block).tap do |listener|
37+
@listeners << listener
38+
end
2939
end
3040

31-
# Stop all listeners & Celluloid
32-
#
33-
# Use it for testing purpose or when you are sure that Celluloid could be
34-
# ended.
35-
#
3641
# This is used by the `listen` binary to handle Ctrl-C
3742
#
3843
def stop
@@ -45,32 +50,6 @@ def stop
4550
listener.stop
4651
end
4752
@listeners = nil
48-
49-
Celluloid.shutdown
50-
end
51-
52-
# Listens to file system modifications broadcast over TCP.
53-
#
54-
# @param [String/Fixnum] target to listen on (hostname:port or port)
55-
#
56-
# @yield [modified, added, removed] the changed files
57-
# @yieldparam [Array<String>] modified the list of modified files
58-
# @yieldparam [Array<String>] added the list of added files
59-
# @yieldparam [Array<String>] removed the list of removed files
60-
#
61-
# @return [Listen::Listener] the listener
62-
#
63-
def on(target, *args, &block)
64-
_add_listener(target, :recipient, *args, &block)
65-
end
66-
67-
private
68-
69-
def _add_listener(*args, &block)
70-
@listeners ||= []
71-
Listener.new(*args, &block).tap do |listener|
72-
@listeners << listener
73-
end
7453
end
7554
end
7655
end

lib/listen/adapter.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ module Adapter
1212
'Learn more at https://github.com/guard/listen#listen-adapters.'
1313

1414
def self.select(options = {})
15-
_log :debug, 'Adapter: considering TCP ...'
16-
return TCP if options[:force_tcp]
1715
_log :debug, 'Adapter: considering polling ...'
1816
return Polling if options[:force_polling]
1917
_log :debug, 'Adapter: considering optimized backend...'
@@ -39,7 +37,7 @@ def self._warn_polling_fallback(options)
3937
end
4038

4139
def self._log(type, message)
42-
Celluloid::Logger.send(type, message)
40+
Listen::Logger.send(type, message)
4341
end
4442
end
4543
end

0 commit comments

Comments
 (0)