listen 2.0.0.beta.1 → 2.0.0.beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +13 -1
- data/lib/listen/adapter/bsd.rb +1 -0
- data/lib/listen/adapter/linux.rb +1 -0
- data/lib/listen/adapter/windows.rb +1 -0
- data/lib/listen/change.rb +7 -4
- data/lib/listen/listener.rb +41 -20
- data/lib/listen/silencer.rb +5 -3
- data/lib/listen/version.rb +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3c0d6aa22397845dc50777764501d381ec45bdb
|
4
|
+
data.tar.gz: 6cbfc75ffc6dde9be05a619696939f2ff2e90bbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ae4ce1cab4d08a3edba293614e20b82b112c1821f3f0e15f653e37b1f8d4ba6a14eb6f65727622faf7651dcf1f347e4f6f0fbae7a52e7359b3f47bc38cbc9a8
|
7
|
+
data.tar.gz: 6b657af0772fe26bf87916534247b52a22ba17afe80d9f515db139a6ef100d6764e6c19ed9bbeafcd0f95d5d6951a2a3578515b17d24d40c43e5a69e25dbf0bc
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Listen [](http://badge.fury.io/rb/listen) [](http://badge.fury.io/rb/listen) [](https://travis-ci.org/guard/listen) [](https://gemnasium.com/guard/listen) [](https://codeclimate.com/github/guard/listen) [](https://coveralls.io/r/guard/listen)
|
2
2
|
|
3
3
|
The Listen gem listens to file modifications and notifies you about the changes.
|
4
4
|
|
@@ -66,6 +66,18 @@ listener.unpause # start listening to changes again
|
|
66
66
|
listener.stop # stop completely the listener
|
67
67
|
```
|
68
68
|
|
69
|
+
### Ignore / ignore!
|
70
|
+
|
71
|
+
Liste ignore some folder and extensions by default (See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer), you can add ignoring patterns with the `ignore` option/method or overwrite default with `ignore!` option/method.
|
72
|
+
|
73
|
+
``` ruby
|
74
|
+
listener = Listen.to('dir/path/to/listen', ignore: /\.txt/) { |modified, added, removed| # ... }
|
75
|
+
listener.start
|
76
|
+
listener.ignore! /\.pkg/ # overwrite all patterns and only ignore pkg extension.
|
77
|
+
listener.ignore /\.rb/ # ignore rb extension in addition of pkg.
|
78
|
+
sleep
|
79
|
+
``
|
80
|
+
|
69
81
|
## Changes callback
|
70
82
|
|
71
83
|
Changes to the listened-to directories gets reported back to the user in a callback.
|
data/lib/listen/adapter/bsd.rb
CHANGED
data/lib/listen/adapter/linux.rb
CHANGED
@@ -42,6 +42,7 @@ module Listen
|
|
42
42
|
# each directory passed to the adapter.
|
43
43
|
#
|
44
44
|
# @return [INotify::Notifier] initialized worker
|
45
|
+
#
|
45
46
|
def _init_worker
|
46
47
|
INotify::Notifier.new.tap do |worker|
|
47
48
|
_directories_path.each { |path| worker.watch(path, *EVENTS, &_worker_callback) }
|
data/lib/listen/change.rb
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
require 'listen/file'
|
2
2
|
require 'listen/directory'
|
3
|
-
require 'listen/silencer'
|
4
3
|
|
5
4
|
module Listen
|
6
5
|
class Change
|
7
6
|
include Celluloid
|
8
7
|
|
9
|
-
attr_accessor :listener
|
8
|
+
attr_accessor :listener
|
10
9
|
|
11
10
|
def initialize(listener)
|
12
11
|
@listener = listener
|
13
|
-
@silencer = Silencer.new(listener.options)
|
14
12
|
end
|
15
13
|
|
16
14
|
def change(path, options)
|
17
|
-
return if
|
15
|
+
return if _silencer.silenced?(path)
|
18
16
|
if change = options[:change]
|
19
17
|
_notify_listener(change, path)
|
20
18
|
else
|
@@ -38,5 +36,10 @@ module Listen
|
|
38
36
|
def _notify_listener(change, path)
|
39
37
|
listener.changes << { change => path }
|
40
38
|
end
|
39
|
+
|
40
|
+
def _silencer
|
41
|
+
Celluloid::Actor[:listen_silencer]
|
42
|
+
end
|
43
|
+
|
41
44
|
end
|
42
45
|
end
|
data/lib/listen/listener.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'listen/adapter'
|
2
2
|
require 'listen/change'
|
3
3
|
require 'listen/record'
|
4
|
+
require 'listen/silencer'
|
4
5
|
|
5
6
|
module Listen
|
6
7
|
class Listener
|
7
|
-
attr_accessor :options, :directories, :paused, :changes, :block
|
8
|
+
attr_accessor :options, :directories, :paused, :changes, :block, :thread
|
8
9
|
|
9
10
|
RELATIVE_PATHS_WITH_MULTIPLE_DIRECTORIES_WARNING_MESSAGE = "The relative_paths option doesn't work when listening to multiple diretories."
|
10
11
|
|
@@ -34,40 +35,66 @@ module Listen
|
|
34
35
|
_signals_trap
|
35
36
|
_init_actors
|
36
37
|
unpause
|
37
|
-
|
38
|
+
Celluloid::Actor[:listen_adapter].async.start
|
38
39
|
@thread = Thread.new { _wait_for_changes }
|
39
40
|
end
|
40
41
|
|
42
|
+
# Terminates all Listen actors and kill the adapter.
|
43
|
+
#
|
41
44
|
def stop
|
42
|
-
|
45
|
+
thread.kill
|
46
|
+
Celluloid::Actor.kill(Celluloid::Actor[:listen_adapter])
|
47
|
+
Celluloid::Actor[:listen_silencer].terminate
|
43
48
|
Celluloid::Actor[:listen_change_pool].terminate
|
44
|
-
|
45
|
-
@thread && @thread.kill
|
49
|
+
Celluloid::Actor[:listen_record].terminate
|
46
50
|
end
|
47
51
|
|
52
|
+
# Pauses listening callback (adapter still running)
|
53
|
+
#
|
48
54
|
def pause
|
49
55
|
@paused = true
|
50
56
|
end
|
51
57
|
|
58
|
+
# Unpauses listening callback
|
59
|
+
#
|
52
60
|
def unpause
|
53
|
-
|
61
|
+
Celluloid::Actor[:listen_record].build
|
54
62
|
@paused = false
|
55
63
|
end
|
56
64
|
|
65
|
+
# Returns true if Listener is paused
|
66
|
+
#
|
67
|
+
# @return [Boolean]
|
68
|
+
#
|
57
69
|
def paused?
|
58
70
|
@paused == true
|
59
71
|
end
|
60
72
|
|
73
|
+
# Returns true if Listener is not paused
|
74
|
+
#
|
75
|
+
# @return [Boolean]
|
76
|
+
#
|
61
77
|
def listen?
|
62
78
|
@paused == false
|
63
79
|
end
|
64
80
|
|
65
|
-
|
66
|
-
|
81
|
+
# Adds ignore patterns to the existing one (See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer)
|
82
|
+
#
|
83
|
+
# @param [Regexp, Hash<Regexp>] new ignoring patterns.
|
84
|
+
#
|
85
|
+
def ignore(regexps)
|
86
|
+
options[:ignore] = [options[:ignore], regexps]
|
87
|
+
Celluloid::Actor[:listen_silencer] = Silencer.new(options)
|
67
88
|
end
|
68
89
|
|
69
|
-
|
70
|
-
|
90
|
+
# Overwrites ignore patterns (See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer)
|
91
|
+
#
|
92
|
+
# @param [Regexp, Hash<Regexp>] new ignoring patterns.
|
93
|
+
#
|
94
|
+
def ignore!(regexps)
|
95
|
+
options.delete(:ignore)
|
96
|
+
options[:ignore!] = regexps
|
97
|
+
Celluloid::Actor[:listen_silencer] = Silencer.new(options)
|
71
98
|
end
|
72
99
|
|
73
100
|
private
|
@@ -89,6 +116,7 @@ module Listen
|
|
89
116
|
|
90
117
|
def _init_actors
|
91
118
|
cores = Celluloid.cores || 2
|
119
|
+
Celluloid::Actor[:listen_silencer] = Silencer.new(options)
|
92
120
|
Celluloid::Actor[:listen_change_pool] = Change.pool(size: cores, args: self)
|
93
121
|
Celluloid::Actor[:listen_adapter] = Adapter.new(self)
|
94
122
|
Celluloid::Actor[:listen_record] = Record.new(self)
|
@@ -100,18 +128,11 @@ module Listen
|
|
100
128
|
end
|
101
129
|
end
|
102
130
|
|
103
|
-
def _build_record_if_needed
|
104
|
-
record && record.build
|
105
|
-
end
|
106
|
-
|
107
131
|
def _wait_for_changes
|
108
132
|
loop do
|
109
133
|
changes = _pop_changes
|
110
|
-
unless changes.
|
111
|
-
block.call(
|
112
|
-
changes[:modified].uniq,
|
113
|
-
changes[:added].uniq,
|
114
|
-
changes[:removed].uniq)
|
134
|
+
unless changes.all? { |_,v| v.empty? }
|
135
|
+
block.call(changes[:modified], changes[:added], changes[:removed])
|
115
136
|
end
|
116
137
|
sleep 0.1
|
117
138
|
end
|
@@ -126,7 +147,7 @@ module Listen
|
|
126
147
|
change = @changes.pop
|
127
148
|
change.each { |k, v| changes[k] << v.to_s }
|
128
149
|
end
|
129
|
-
changes
|
150
|
+
changes.each { |_, v| v.uniq! }
|
130
151
|
end
|
131
152
|
end
|
132
153
|
end
|
data/lib/listen/silencer.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module Listen
|
2
2
|
class Silencer
|
3
|
+
include Celluloid
|
4
|
+
|
3
5
|
# The default list of directories that get ignored.
|
4
|
-
DEFAULT_IGNORED_DIRECTORIES = %w[.rbx .bundle .git .svn .hg bundle log tmp vendor]
|
6
|
+
DEFAULT_IGNORED_DIRECTORIES = %w[.rbx .bundle .git .svn .hg bundle log tmp vendor/ruby]
|
5
7
|
|
6
8
|
# The default list of files that get ignored.
|
7
9
|
DEFAULT_IGNORED_EXTENSIONS = %w[.DS_Store]
|
@@ -14,7 +16,7 @@ module Listen
|
|
14
16
|
end
|
15
17
|
|
16
18
|
def silenced?(path)
|
17
|
-
patterns.any? { |pattern|
|
19
|
+
patterns.any? { |pattern| path.to_s =~ pattern }
|
18
20
|
end
|
19
21
|
|
20
22
|
private
|
@@ -23,7 +25,7 @@ module Listen
|
|
23
25
|
@patterns = []
|
24
26
|
@patterns << _default_patterns unless options[:ignore!]
|
25
27
|
@patterns << options[:ignore] << options[:ignore!]
|
26
|
-
@patterns.compact
|
28
|
+
@patterns.compact!
|
27
29
|
@patterns.flatten!
|
28
30
|
end
|
29
31
|
|
data/lib/listen/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: listen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.beta.
|
4
|
+
version: 2.0.0.beta.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thibaud Guillaume-Gentil
|
8
|
-
- Maher Sallam
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-16 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: celluloid
|
@@ -97,9 +96,7 @@ dependencies:
|
|
97
96
|
version: '0'
|
98
97
|
description: The Listen gem listens to file modifications and notifies you about the
|
99
98
|
changes. Works everywhere!
|
100
|
-
email:
|
101
|
-
- thibaud@thibaud.me
|
102
|
-
- maher@sallam.me
|
99
|
+
email: thibaud@thibaud.me
|
103
100
|
executables: []
|
104
101
|
extensions: []
|
105
102
|
extra_rdoc_files: []
|