listen 2.5.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/README.md +9 -1
- data/bin/listen +7 -0
- data/lib/listen/cli.rb +60 -0
- data/lib/listen/file.rb +17 -8
- data/lib/listen/version.rb +1 -1
- data/listen.gemspec +1 -0
- data/spec/lib/listen/file_spec.rb +13 -17
- data/spec/spec_helper.rb +1 -1
- data/spec/support/acceptance_helper.rb +1 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c36c878c828e97095cc4497053d1243846ab65e
|
4
|
+
data.tar.gz: 1a1b6cb5c69ac240031139da5c8799a9fb621370
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8cc54bd15b9e71184141775941b546acf42103d24f47f1eeaf713ba2d1f3c01fd7fa6e46995415418f84ad532572a41a79dd4966bf36bbdada4c5d562fd6646
|
7
|
+
data.tar.gz: d0c4813cf6417449bb38687dbcc723993a9b59952a67f6bb6ac58eed65d6bd0d67eebd10910968a291bcfa540097ef81084cddb7af9085ea75b6ec4bdf89f43b
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -190,6 +190,7 @@ Here are some things you could try to avoid forcing polling.
|
|
190
190
|
* Move or rename the listened directory.
|
191
191
|
* Update/reboot your OS.
|
192
192
|
* Increase latency.
|
193
|
+
* If running Linux, check and see if you need package inotify-tools
|
193
194
|
|
194
195
|
If your application keeps using the polling-adapter and you can't figure out why, feel free to [open an issue](https://github.com/guard/listen/issues/new) (and be sure to [give all the details](https://github.com/guard/listen/blob/master/CONTRIBUTING.md)).
|
195
196
|
|
@@ -197,7 +198,7 @@ If your application keeps using the polling-adapter and you can't figure out why
|
|
197
198
|
|
198
199
|
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 [Vagrant](https://github.com/mitchellh/vagrant).
|
199
200
|
|
200
|
-
To broadcast events over TCP, use the `forward_to` option with an address - just a port or a hostname/port combination:
|
201
|
+
To broadcast events over TCP programmatically, use the `forward_to` option with an address - just a port or a hostname/port combination:
|
201
202
|
|
202
203
|
```ruby
|
203
204
|
listener = Listen.to 'path/to/app', forward_to: '10.0.0.2:4000' do |modified, added, removed|
|
@@ -208,6 +209,13 @@ listener.start
|
|
208
209
|
sleep
|
209
210
|
```
|
210
211
|
|
212
|
+
As a convenience, the `listen` script is supplied which listens to a directory and forwards the events to a network address
|
213
|
+
|
214
|
+
```bash
|
215
|
+
listen -f "10.0.0.2:4000"
|
216
|
+
listen -v -d "/projects/my_project" -f "10.0.0.2:4000"
|
217
|
+
```
|
218
|
+
|
211
219
|
To connect to a broadcasting listener as a recipient, specify its address using `Listen.on`:
|
212
220
|
|
213
221
|
```ruby
|
data/bin/listen
ADDED
data/lib/listen/cli.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'Listen'
|
3
|
+
|
4
|
+
module Listen
|
5
|
+
class CLI < Thor
|
6
|
+
default_task :start
|
7
|
+
|
8
|
+
desc 'start', 'Starts Listen'
|
9
|
+
|
10
|
+
class_option :verbose,
|
11
|
+
type: :boolean,
|
12
|
+
default: false,
|
13
|
+
aliases: '-v',
|
14
|
+
banner: 'Verbose'
|
15
|
+
|
16
|
+
class_option :forward,
|
17
|
+
type: :string,
|
18
|
+
default: '127.0.0.1:4000',
|
19
|
+
aliases: '-f',
|
20
|
+
banner: 'The address to forward filesystem events'
|
21
|
+
|
22
|
+
class_option :directory,
|
23
|
+
type: :string,
|
24
|
+
default: '.',
|
25
|
+
aliases: '-d',
|
26
|
+
banner: 'The directory to listen to'
|
27
|
+
|
28
|
+
|
29
|
+
def start
|
30
|
+
Listen::Forwarder.new(options).start
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
class Forwarder
|
36
|
+
def initialize(options)
|
37
|
+
@options = options
|
38
|
+
end
|
39
|
+
|
40
|
+
def start
|
41
|
+
puts "Starting listen..."
|
42
|
+
address = @options[:forward]
|
43
|
+
directory = @options[:directory]
|
44
|
+
callback = Proc.new do |modified, added, removed|
|
45
|
+
if @options[:verbose]
|
46
|
+
puts "+ #{added}" unless added.empty?
|
47
|
+
puts "- #{removed}" unless removed.empty?
|
48
|
+
puts "> #{modified}" unless modified.empty?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
listener = Listen.to directory, forward_to: address, &callback
|
53
|
+
listener.start
|
54
|
+
|
55
|
+
while listener.listen?
|
56
|
+
sleep 0.5
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/listen/file.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Listen
|
2
2
|
class File
|
3
|
-
attr_accessor :listener, :path, :data
|
3
|
+
attr_accessor :listener, :path, :data, :md5
|
4
4
|
|
5
5
|
def initialize(listener, path)
|
6
6
|
@listener = listener
|
@@ -51,10 +51,21 @@ module Listen
|
|
51
51
|
_mode != _record_data[:mode]
|
52
52
|
end
|
53
53
|
|
54
|
-
# Only useful on Darwin because of the file mtime second precision
|
54
|
+
# Only useful on Darwin because of the file mtime second precision.
|
55
|
+
# Only check if in the same seconds (mtime == current time).
|
56
|
+
# MD5 is eager loaded, so the first time it'll always return false.
|
55
57
|
#
|
56
58
|
def _content_modified?
|
57
|
-
|
59
|
+
return false unless RbConfig::CONFIG['target_os'] =~ /darwin/i
|
60
|
+
return false unless _mtime.to_i == Time.now.to_i
|
61
|
+
|
62
|
+
_set_md5
|
63
|
+
if _record_data[:md5]
|
64
|
+
md5 != _record_data[:md5]
|
65
|
+
else
|
66
|
+
_set_record_data
|
67
|
+
false
|
68
|
+
end
|
58
69
|
end
|
59
70
|
|
60
71
|
def _set_record_data
|
@@ -66,11 +77,9 @@ module Listen
|
|
66
77
|
_record.async.unset_path(path)
|
67
78
|
end
|
68
79
|
|
69
|
-
# Only Darwin need md5 comparaison because of the file mtime second precision
|
70
|
-
#
|
71
80
|
def _new_data
|
72
81
|
data = { mtime: _mtime, mode: _mode }
|
73
|
-
data[:md5] =
|
82
|
+
data[:md5] = md5 if md5
|
74
83
|
data
|
75
84
|
end
|
76
85
|
|
@@ -100,8 +109,8 @@ module Listen
|
|
100
109
|
nil
|
101
110
|
end
|
102
111
|
|
103
|
-
def
|
104
|
-
@md5
|
112
|
+
def _set_md5
|
113
|
+
@md5 = Digest::MD5.file(path).digest
|
105
114
|
rescue
|
106
115
|
nil
|
107
116
|
end
|
data/lib/listen/version.rb
CHANGED
data/listen.gemspec
CHANGED
@@ -11,13 +11,7 @@ describe Listen::File do
|
|
11
11
|
describe "#change" do
|
12
12
|
let(:file_path) { path.join('file.rb') }
|
13
13
|
let(:file) { Listen::File.new(listener, file_path) }
|
14
|
-
let(:expected_data) {
|
15
|
-
if darwin?
|
16
|
-
{ type: 'File', mtime: kind_of(Float), mode: kind_of(Integer), md5: kind_of(String) }
|
17
|
-
else
|
18
|
-
{ type: 'File', mtime: kind_of(Float), mode: kind_of(Integer) }
|
19
|
-
end
|
20
|
-
}
|
14
|
+
let(:expected_data) { { type: 'File', mtime: kind_of(Float), mode: kind_of(Integer) } }
|
21
15
|
|
22
16
|
context "path present in record" do
|
23
17
|
let(:record_mtime) { nil }
|
@@ -55,7 +49,6 @@ describe Listen::File do
|
|
55
49
|
context "same record path mtime" do
|
56
50
|
let(:record_mtime) { ::File.lstat(file_path).mtime.to_f }
|
57
51
|
let(:record_mode) { ::File.lstat(file_path).mode }
|
58
|
-
let(:record_md5) { Digest::MD5.file(file_path).digest }
|
59
52
|
|
60
53
|
context "same record path mode" do
|
61
54
|
it "returns nil" do
|
@@ -77,15 +70,18 @@ describe Listen::File do
|
|
77
70
|
end
|
78
71
|
end
|
79
72
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
73
|
+
if darwin?
|
74
|
+
context "different record path md5" do
|
75
|
+
let(:record_md5) { 'foo' }
|
76
|
+
let(:expected_data) { { type: 'File', mtime: kind_of(Float), mode: kind_of(Integer), md5: kind_of(String) } }
|
77
|
+
|
78
|
+
it "returns modified" do
|
79
|
+
expect(file.change).to eq :modified
|
80
|
+
end
|
81
|
+
it "sets path in record with expected data" do
|
82
|
+
expect(record.async).to receive(:set_path).with(file_path, expected_data)
|
83
|
+
file.change
|
84
|
+
end
|
89
85
|
end
|
90
86
|
end
|
91
87
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: listen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thibaud Guillaume-Gentil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|
@@ -125,7 +125,8 @@ dependencies:
|
|
125
125
|
description: The Listen gem listens to file modifications and notifies you about the
|
126
126
|
changes. Works everywhere!
|
127
127
|
email: thibaud@thibaud.gg
|
128
|
-
executables:
|
128
|
+
executables:
|
129
|
+
- listen
|
129
130
|
extensions: []
|
130
131
|
extra_rdoc_files: []
|
131
132
|
files:
|
@@ -140,6 +141,7 @@ files:
|
|
140
141
|
- LICENSE.txt
|
141
142
|
- README.md
|
142
143
|
- Rakefile
|
144
|
+
- bin/listen
|
143
145
|
- lib/listen.rb
|
144
146
|
- lib/listen/adapter.rb
|
145
147
|
- lib/listen/adapter/base.rb
|
@@ -150,6 +152,7 @@ files:
|
|
150
152
|
- lib/listen/adapter/tcp.rb
|
151
153
|
- lib/listen/adapter/windows.rb
|
152
154
|
- lib/listen/change.rb
|
155
|
+
- lib/listen/cli.rb
|
153
156
|
- lib/listen/directory.rb
|
154
157
|
- lib/listen/file.rb
|
155
158
|
- lib/listen/listener.rb
|