guard 0.8.4 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +348 -330
- data/LICENSE +19 -19
- data/README.md +464 -431
- data/bin/guard +6 -6
- data/lib/guard.rb +452 -414
- data/lib/guard/cli.rb +119 -178
- data/lib/guard/dsl.rb +370 -370
- data/lib/guard/dsl_describer.rb +150 -60
- data/lib/guard/group.rb +37 -37
- data/lib/guard/guard.rb +129 -113
- data/lib/guard/hook.rb +118 -118
- data/lib/guard/interactor.rb +110 -44
- data/lib/guard/listener.rb +350 -350
- data/lib/guard/listeners/darwin.rb +66 -66
- data/lib/guard/listeners/linux.rb +97 -97
- data/lib/guard/listeners/polling.rb +55 -55
- data/lib/guard/listeners/windows.rb +61 -61
- data/lib/guard/notifier.rb +290 -211
- data/lib/guard/templates/Guardfile +2 -2
- data/lib/guard/ui.rb +193 -188
- data/lib/guard/version.rb +6 -6
- data/lib/guard/watcher.rb +114 -110
- data/man/guard.1 +93 -93
- data/man/guard.1.html +176 -176
- metadata +107 -59
@@ -1,66 +1,66 @@
|
|
1
|
-
module Guard
|
2
|
-
|
3
|
-
# Listener implementation for Mac OS X `FSEvents`.
|
4
|
-
#
|
5
|
-
class Darwin < Listener
|
6
|
-
|
7
|
-
# Initialize the Listener.
|
8
|
-
#
|
9
|
-
def initialize(*)
|
10
|
-
super
|
11
|
-
@fsevent = FSEvent.new
|
12
|
-
end
|
13
|
-
|
14
|
-
# Start the listener.
|
15
|
-
#
|
16
|
-
def start
|
17
|
-
super
|
18
|
-
worker.run
|
19
|
-
end
|
20
|
-
|
21
|
-
# Stop the listener.
|
22
|
-
#
|
23
|
-
def stop
|
24
|
-
super
|
25
|
-
worker.stop
|
26
|
-
end
|
27
|
-
|
28
|
-
# Check if the listener is usable on the current OS.
|
29
|
-
#
|
30
|
-
# @return [Boolean] whether usable or not
|
31
|
-
#
|
32
|
-
def self.usable?
|
33
|
-
require 'rb-fsevent'
|
34
|
-
if !defined?(FSEvent::VERSION) || (defined?(Gem::Version) &&
|
35
|
-
Gem::Version.new(FSEvent::VERSION) < Gem::Version.new('0.4.0'))
|
36
|
-
UI.info 'Please update rb-fsevent (>= 0.4.0)'
|
37
|
-
false
|
38
|
-
else
|
39
|
-
true
|
40
|
-
end
|
41
|
-
rescue LoadError
|
42
|
-
UI.info 'Please install rb-fsevent gem for Mac OSX FSEvents support'
|
43
|
-
false
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
# Get the listener worker.
|
49
|
-
#
|
50
|
-
def worker
|
51
|
-
@fsevent
|
52
|
-
end
|
53
|
-
|
54
|
-
# Watch the given directory for file changes.
|
55
|
-
#
|
56
|
-
# @param [String] directory the directory to watch
|
57
|
-
#
|
58
|
-
def watch(directory)
|
59
|
-
worker.watch(directory) do |modified_dirs|
|
60
|
-
files = modified_files(modified_dirs)
|
61
|
-
@callback.call(files) unless files.empty?
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
1
|
+
module Guard
|
2
|
+
|
3
|
+
# Listener implementation for Mac OS X `FSEvents`.
|
4
|
+
#
|
5
|
+
class Darwin < Listener
|
6
|
+
|
7
|
+
# Initialize the Listener.
|
8
|
+
#
|
9
|
+
def initialize(*)
|
10
|
+
super
|
11
|
+
@fsevent = FSEvent.new
|
12
|
+
end
|
13
|
+
|
14
|
+
# Start the listener.
|
15
|
+
#
|
16
|
+
def start
|
17
|
+
super
|
18
|
+
worker.run
|
19
|
+
end
|
20
|
+
|
21
|
+
# Stop the listener.
|
22
|
+
#
|
23
|
+
def stop
|
24
|
+
super
|
25
|
+
worker.stop
|
26
|
+
end
|
27
|
+
|
28
|
+
# Check if the listener is usable on the current OS.
|
29
|
+
#
|
30
|
+
# @return [Boolean] whether usable or not
|
31
|
+
#
|
32
|
+
def self.usable?
|
33
|
+
require 'rb-fsevent'
|
34
|
+
if !defined?(FSEvent::VERSION) || (defined?(Gem::Version) &&
|
35
|
+
Gem::Version.new(FSEvent::VERSION) < Gem::Version.new('0.4.0'))
|
36
|
+
UI.info 'Please update rb-fsevent (>= 0.4.0)'
|
37
|
+
false
|
38
|
+
else
|
39
|
+
true
|
40
|
+
end
|
41
|
+
rescue LoadError
|
42
|
+
UI.info 'Please install rb-fsevent gem for Mac OSX FSEvents support'
|
43
|
+
false
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# Get the listener worker.
|
49
|
+
#
|
50
|
+
def worker
|
51
|
+
@fsevent
|
52
|
+
end
|
53
|
+
|
54
|
+
# Watch the given directory for file changes.
|
55
|
+
#
|
56
|
+
# @param [String] directory the directory to watch
|
57
|
+
#
|
58
|
+
def watch(directory)
|
59
|
+
worker.watch(directory) do |modified_dirs|
|
60
|
+
files = modified_files(modified_dirs)
|
61
|
+
@callback.call(files) unless files.empty?
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -1,97 +1,97 @@
|
|
1
|
-
module Guard
|
2
|
-
|
3
|
-
# Listener implementation for Linux `inotify`.
|
4
|
-
#
|
5
|
-
class Linux < Listener
|
6
|
-
|
7
|
-
# Initialize the Listener.
|
8
|
-
#
|
9
|
-
def initialize(*)
|
10
|
-
super
|
11
|
-
@inotify = INotify::Notifier.new
|
12
|
-
@files = []
|
13
|
-
@latency = 0.5
|
14
|
-
end
|
15
|
-
|
16
|
-
# Start the listener.
|
17
|
-
#
|
18
|
-
def start
|
19
|
-
@stop = false
|
20
|
-
super
|
21
|
-
watch_change unless watch_change?
|
22
|
-
end
|
23
|
-
|
24
|
-
# Stop the listener.
|
25
|
-
#
|
26
|
-
def stop
|
27
|
-
super
|
28
|
-
@stop = true
|
29
|
-
end
|
30
|
-
|
31
|
-
# Check if the listener is usable on the current OS.
|
32
|
-
#
|
33
|
-
# @return [Boolean] whether usable or not
|
34
|
-
#
|
35
|
-
def self.usable?
|
36
|
-
require 'rb-inotify'
|
37
|
-
if !defined?(INotify::VERSION) || (defined?(Gem::Version) &&
|
38
|
-
Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.8.5'))
|
39
|
-
UI.info 'Please update rb-inotify (>= 0.8.5)'
|
40
|
-
false
|
41
|
-
else
|
42
|
-
true
|
43
|
-
end
|
44
|
-
rescue LoadError
|
45
|
-
UI.info 'Please install rb-inotify gem for Linux inotify support'
|
46
|
-
false
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
# Get the listener worker.
|
52
|
-
#
|
53
|
-
def worker
|
54
|
-
@inotify
|
55
|
-
end
|
56
|
-
|
57
|
-
# Watch the given directory for file changes.
|
58
|
-
#
|
59
|
-
# @param [String] directory the directory to watch
|
60
|
-
#
|
61
|
-
def watch(directory)
|
62
|
-
worker.watch(directory, :recursive, :attrib, :create, :move_self, :close_write) do |event|
|
63
|
-
unless event.name == "" # Event on root directory
|
64
|
-
@files << event.absolute_name
|
65
|
-
end
|
66
|
-
end
|
67
|
-
rescue Interrupt
|
68
|
-
end
|
69
|
-
|
70
|
-
# Test if inotify is watching for changes.
|
71
|
-
#
|
72
|
-
# @return [Boolean] whether inotify is active or not
|
73
|
-
#
|
74
|
-
def watch_change?
|
75
|
-
!!@watch_change
|
76
|
-
end
|
77
|
-
|
78
|
-
# Watch for file system changes.
|
79
|
-
#
|
80
|
-
def watch_change
|
81
|
-
@watch_change = true
|
82
|
-
until @stop
|
83
|
-
if RbConfig::CONFIG['build'] =~ /java/ || IO.select([worker.to_io], [], [], @latency)
|
84
|
-
break if @stop
|
85
|
-
|
86
|
-
sleep(@latency)
|
87
|
-
worker.process
|
88
|
-
|
89
|
-
files = modified_files(@files.shift(@files.size).map { |f| File.dirname(f) }.uniq)
|
90
|
-
@callback.call(files) unless files.empty?
|
91
|
-
end
|
92
|
-
end
|
93
|
-
@watch_change = false
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
end
|
1
|
+
module Guard
|
2
|
+
|
3
|
+
# Listener implementation for Linux `inotify`.
|
4
|
+
#
|
5
|
+
class Linux < Listener
|
6
|
+
|
7
|
+
# Initialize the Listener.
|
8
|
+
#
|
9
|
+
def initialize(*)
|
10
|
+
super
|
11
|
+
@inotify = INotify::Notifier.new
|
12
|
+
@files = []
|
13
|
+
@latency = 0.5
|
14
|
+
end
|
15
|
+
|
16
|
+
# Start the listener.
|
17
|
+
#
|
18
|
+
def start
|
19
|
+
@stop = false
|
20
|
+
super
|
21
|
+
watch_change unless watch_change?
|
22
|
+
end
|
23
|
+
|
24
|
+
# Stop the listener.
|
25
|
+
#
|
26
|
+
def stop
|
27
|
+
super
|
28
|
+
@stop = true
|
29
|
+
end
|
30
|
+
|
31
|
+
# Check if the listener is usable on the current OS.
|
32
|
+
#
|
33
|
+
# @return [Boolean] whether usable or not
|
34
|
+
#
|
35
|
+
def self.usable?
|
36
|
+
require 'rb-inotify'
|
37
|
+
if !defined?(INotify::VERSION) || (defined?(Gem::Version) &&
|
38
|
+
Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.8.5'))
|
39
|
+
UI.info 'Please update rb-inotify (>= 0.8.5)'
|
40
|
+
false
|
41
|
+
else
|
42
|
+
true
|
43
|
+
end
|
44
|
+
rescue LoadError
|
45
|
+
UI.info 'Please install rb-inotify gem for Linux inotify support'
|
46
|
+
false
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# Get the listener worker.
|
52
|
+
#
|
53
|
+
def worker
|
54
|
+
@inotify
|
55
|
+
end
|
56
|
+
|
57
|
+
# Watch the given directory for file changes.
|
58
|
+
#
|
59
|
+
# @param [String] directory the directory to watch
|
60
|
+
#
|
61
|
+
def watch(directory)
|
62
|
+
worker.watch(directory, :recursive, :attrib, :create, :move_self, :close_write) do |event|
|
63
|
+
unless event.name == "" # Event on root directory
|
64
|
+
@files << event.absolute_name
|
65
|
+
end
|
66
|
+
end
|
67
|
+
rescue Interrupt
|
68
|
+
end
|
69
|
+
|
70
|
+
# Test if inotify is watching for changes.
|
71
|
+
#
|
72
|
+
# @return [Boolean] whether inotify is active or not
|
73
|
+
#
|
74
|
+
def watch_change?
|
75
|
+
!!@watch_change
|
76
|
+
end
|
77
|
+
|
78
|
+
# Watch for file system changes.
|
79
|
+
#
|
80
|
+
def watch_change
|
81
|
+
@watch_change = true
|
82
|
+
until @stop
|
83
|
+
if RbConfig::CONFIG['build'] =~ /java/ || IO.select([worker.to_io], [], [], @latency)
|
84
|
+
break if @stop
|
85
|
+
|
86
|
+
sleep(@latency)
|
87
|
+
worker.process
|
88
|
+
|
89
|
+
files = modified_files(@files.shift(@files.size).map { |f| File.dirname(f) }.uniq)
|
90
|
+
@callback.call(files) unless files.empty?
|
91
|
+
end
|
92
|
+
end
|
93
|
+
@watch_change = false
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
@@ -1,55 +1,55 @@
|
|
1
|
-
module Guard
|
2
|
-
|
3
|
-
# Polling listener that works cross-platform and
|
4
|
-
# has no dependencies. This is the listener that
|
5
|
-
# uses the most CPU processing power and has higher
|
6
|
-
# file IO that the other implementations.
|
7
|
-
#
|
8
|
-
class Polling < Listener
|
9
|
-
|
10
|
-
# Initialize the Listener.
|
11
|
-
#
|
12
|
-
def initialize(*)
|
13
|
-
super
|
14
|
-
@latency = 1.5
|
15
|
-
end
|
16
|
-
|
17
|
-
# Start the listener.
|
18
|
-
#
|
19
|
-
def start
|
20
|
-
@stop = false
|
21
|
-
super
|
22
|
-
watch_change
|
23
|
-
end
|
24
|
-
|
25
|
-
# Stop the listener.
|
26
|
-
#
|
27
|
-
def stop
|
28
|
-
super
|
29
|
-
@stop = true
|
30
|
-
end
|
31
|
-
|
32
|
-
# Watch the given directory for file changes.
|
33
|
-
#
|
34
|
-
# @param [String] directory the directory to watch
|
35
|
-
#
|
36
|
-
def watch(directory)
|
37
|
-
@existing = all_files
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
# Watch for file system changes.
|
43
|
-
#
|
44
|
-
def watch_change
|
45
|
-
until @stop
|
46
|
-
start = Time.now.to_f
|
47
|
-
files = modified_files([@directory], :all => true)
|
48
|
-
@callback.call(files) unless files.empty?
|
49
|
-
nap_time = @latency - (Time.now.to_f - start)
|
50
|
-
sleep(nap_time) if nap_time > 0
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
1
|
+
module Guard
|
2
|
+
|
3
|
+
# Polling listener that works cross-platform and
|
4
|
+
# has no dependencies. This is the listener that
|
5
|
+
# uses the most CPU processing power and has higher
|
6
|
+
# file IO that the other implementations.
|
7
|
+
#
|
8
|
+
class Polling < Listener
|
9
|
+
|
10
|
+
# Initialize the Listener.
|
11
|
+
#
|
12
|
+
def initialize(*)
|
13
|
+
super
|
14
|
+
@latency = 1.5
|
15
|
+
end
|
16
|
+
|
17
|
+
# Start the listener.
|
18
|
+
#
|
19
|
+
def start
|
20
|
+
@stop = false
|
21
|
+
super
|
22
|
+
watch_change
|
23
|
+
end
|
24
|
+
|
25
|
+
# Stop the listener.
|
26
|
+
#
|
27
|
+
def stop
|
28
|
+
super
|
29
|
+
@stop = true
|
30
|
+
end
|
31
|
+
|
32
|
+
# Watch the given directory for file changes.
|
33
|
+
#
|
34
|
+
# @param [String] directory the directory to watch
|
35
|
+
#
|
36
|
+
def watch(directory)
|
37
|
+
@existing = all_files
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
# Watch for file system changes.
|
43
|
+
#
|
44
|
+
def watch_change
|
45
|
+
until @stop
|
46
|
+
start = Time.now.to_f
|
47
|
+
files = modified_files([@directory], :all => true)
|
48
|
+
@callback.call(files) unless files.empty?
|
49
|
+
nap_time = @latency - (Time.now.to_f - start)
|
50
|
+
sleep(nap_time) if nap_time > 0
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -1,61 +1,61 @@
|
|
1
|
-
module Guard
|
2
|
-
|
3
|
-
# Listener implementation for Windows `fchange`.
|
4
|
-
#
|
5
|
-
class Windows < Listener
|
6
|
-
|
7
|
-
# Initialize the Listener.
|
8
|
-
#
|
9
|
-
def initialize(*)
|
10
|
-
super
|
11
|
-
@fchange = FChange::Notifier.new
|
12
|
-
end
|
13
|
-
|
14
|
-
# Start the listener.
|
15
|
-
#
|
16
|
-
def start
|
17
|
-
super
|
18
|
-
worker.run
|
19
|
-
end
|
20
|
-
|
21
|
-
# Stop the listener.
|
22
|
-
#
|
23
|
-
def stop
|
24
|
-
super
|
25
|
-
worker.stop
|
26
|
-
end
|
27
|
-
|
28
|
-
# Check if the listener is usable on the current OS.
|
29
|
-
#
|
30
|
-
# @return [Boolean] whether usable or not
|
31
|
-
#
|
32
|
-
def self.usable?
|
33
|
-
require 'rb-fchange'
|
34
|
-
true
|
35
|
-
rescue LoadError
|
36
|
-
UI.info 'Please install rb-fchange gem for Windows file events support'
|
37
|
-
false
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
# Watch the given directory for file changes.
|
43
|
-
#
|
44
|
-
# @param [String] directory the directory to watch
|
45
|
-
#
|
46
|
-
def watch(directory)
|
47
|
-
worker.watch(directory, :all_events, :recursive) do |event|
|
48
|
-
paths = [File.expand_path(event.watcher.path)]
|
49
|
-
files = modified_files(paths, :all => true)
|
50
|
-
@callback.call(files) unless files.empty?
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# Get the listener worker.
|
55
|
-
#
|
56
|
-
def worker
|
57
|
-
@fchange
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
1
|
+
module Guard
|
2
|
+
|
3
|
+
# Listener implementation for Windows `fchange`.
|
4
|
+
#
|
5
|
+
class Windows < Listener
|
6
|
+
|
7
|
+
# Initialize the Listener.
|
8
|
+
#
|
9
|
+
def initialize(*)
|
10
|
+
super
|
11
|
+
@fchange = FChange::Notifier.new
|
12
|
+
end
|
13
|
+
|
14
|
+
# Start the listener.
|
15
|
+
#
|
16
|
+
def start
|
17
|
+
super
|
18
|
+
worker.run
|
19
|
+
end
|
20
|
+
|
21
|
+
# Stop the listener.
|
22
|
+
#
|
23
|
+
def stop
|
24
|
+
super
|
25
|
+
worker.stop
|
26
|
+
end
|
27
|
+
|
28
|
+
# Check if the listener is usable on the current OS.
|
29
|
+
#
|
30
|
+
# @return [Boolean] whether usable or not
|
31
|
+
#
|
32
|
+
def self.usable?
|
33
|
+
require 'rb-fchange'
|
34
|
+
true
|
35
|
+
rescue LoadError
|
36
|
+
UI.info 'Please install rb-fchange gem for Windows file events support'
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
# Watch the given directory for file changes.
|
43
|
+
#
|
44
|
+
# @param [String] directory the directory to watch
|
45
|
+
#
|
46
|
+
def watch(directory)
|
47
|
+
worker.watch(directory, :all_events, :recursive) do |event|
|
48
|
+
paths = [File.expand_path(event.watcher.path)]
|
49
|
+
files = modified_files(paths, :all => true)
|
50
|
+
@callback.call(files) unless files.empty?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Get the listener worker.
|
55
|
+
#
|
56
|
+
def worker
|
57
|
+
@fchange
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|