guard 0.8.0 → 0.8.1

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.
@@ -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,98 +1,98 @@
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
- sleep(@latency)
30
- end
31
-
32
- # Check if the listener is usable on the current OS.
33
- #
34
- # @return [Boolean] whether usable or not
35
- #
36
- def self.usable?
37
- require 'rb-inotify'
38
- if !defined?(INotify::VERSION) || (defined?(Gem::Version) &&
39
- Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.8.5'))
40
- UI.info 'Please update rb-inotify (>= 0.8.5)'
41
- false
42
- else
43
- true
44
- end
45
- rescue LoadError
46
- UI.info 'Please install rb-inotify gem for Linux inotify support'
47
- false
48
- end
49
-
50
- private
51
-
52
- # Get the listener worker.
53
- #
54
- def worker
55
- @inotify
56
- end
57
-
58
- # Watch the given directory for file changes.
59
- #
60
- # @param [String] directory the directory to watch
61
- #
62
- def watch(directory)
63
- worker.watch(directory, :recursive, :attrib, :create, :move_self, :close_write) do |event|
64
- unless event.name == "" # Event on root directory
65
- @files << event.absolute_name
66
- end
67
- end
68
- rescue Interrupt
69
- end
70
-
71
- # Test if inotify is watching for changes.
72
- #
73
- # @return [Boolean] whether inotify is active or not
74
- #
75
- def watch_change?
76
- !!@watch_change
77
- end
78
-
79
- # Watch for file system changes.
80
- #
81
- def watch_change
82
- @watch_change = true
83
- until @stop
84
- if RbConfig::CONFIG['build'] =~ /java/ || IO.select([worker.to_io], [], [], @latency)
85
- break if @stop
86
-
87
- sleep(@latency)
88
- worker.process
89
-
90
- files = modified_files(@files.shift(@files.size).map { |f| File.dirname(f) }.uniq)
91
- @callback.call(files) unless files.empty?
92
- end
93
- end
94
- @watch_change = false
95
- end
96
-
97
- end
98
- 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
+ sleep(@latency)
30
+ end
31
+
32
+ # Check if the listener is usable on the current OS.
33
+ #
34
+ # @return [Boolean] whether usable or not
35
+ #
36
+ def self.usable?
37
+ require 'rb-inotify'
38
+ if !defined?(INotify::VERSION) || (defined?(Gem::Version) &&
39
+ Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.8.5'))
40
+ UI.info 'Please update rb-inotify (>= 0.8.5)'
41
+ false
42
+ else
43
+ true
44
+ end
45
+ rescue LoadError
46
+ UI.info 'Please install rb-inotify gem for Linux inotify support'
47
+ false
48
+ end
49
+
50
+ private
51
+
52
+ # Get the listener worker.
53
+ #
54
+ def worker
55
+ @inotify
56
+ end
57
+
58
+ # Watch the given directory for file changes.
59
+ #
60
+ # @param [String] directory the directory to watch
61
+ #
62
+ def watch(directory)
63
+ worker.watch(directory, :recursive, :attrib, :create, :move_self, :close_write) do |event|
64
+ unless event.name == "" # Event on root directory
65
+ @files << event.absolute_name
66
+ end
67
+ end
68
+ rescue Interrupt
69
+ end
70
+
71
+ # Test if inotify is watching for changes.
72
+ #
73
+ # @return [Boolean] whether inotify is active or not
74
+ #
75
+ def watch_change?
76
+ !!@watch_change
77
+ end
78
+
79
+ # Watch for file system changes.
80
+ #
81
+ def watch_change
82
+ @watch_change = true
83
+ until @stop
84
+ if RbConfig::CONFIG['build'] =~ /java/ || IO.select([worker.to_io], [], [], @latency)
85
+ break if @stop
86
+
87
+ sleep(@latency)
88
+ worker.process
89
+
90
+ files = modified_files(@files.shift(@files.size).map { |f| File.dirname(f) }.uniq)
91
+ @callback.call(files) unless files.empty?
92
+ end
93
+ end
94
+ @watch_change = false
95
+ end
96
+
97
+ end
98
+ 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