listen 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
- ## 0.3.2 - 4 Mars, 2012
1
+ ## 0.3.3 - March 6, 2012
2
+
3
+ ### Improvements
4
+
5
+ - Improve pause/unpause. ([@thibaudgg][])
6
+
7
+ ## 0.3.2 - March 4, 2012
2
8
 
3
9
  ### New features
4
10
 
data/README.md CHANGED
@@ -101,8 +101,9 @@ Listener can also easily be paused/unpaused:
101
101
  ``` ruby
102
102
  listener = Listen.to('dir/path/to/listen')
103
103
  listener.start # enter the run loop
104
- listener.pause # stop the run loop and enter the wait loop
105
- listener.unpause # re-enter the run loop
104
+ listener.pause # stop listening changes
105
+ listener.paused? => true
106
+ listener.unpause
106
107
  listener.stop
107
108
  ```
108
109
 
@@ -127,6 +128,7 @@ When the OS-specific adapter doesn't work the Listen gem automatically falls bac
127
128
  Here some things to try to avoiding this fallback:
128
129
 
129
130
  * [Update your Dropbox client](http://www.dropbox.com/downloading) (if used).
131
+ * Increase latency. (Please [open an issue](https://github.com/guard/listen/issues/new) if you think that default is too low.)
130
132
  * Move or rename the listened folder.
131
133
  * Update/reboot your OS.
132
134
 
@@ -2,7 +2,7 @@ require 'rbconfig'
2
2
 
3
3
  module Listen
4
4
  class Adapter
5
- attr_accessor :latency
5
+ attr_accessor :latency, :paused
6
6
 
7
7
  # The default delay between checking for changes.
8
8
  DEFAULT_LATENCY = 0.1
@@ -58,6 +58,7 @@ module Listen
58
58
  @callback = callback
59
59
  @latency ||= DEFAULT_LATENCY
60
60
  @latency = options[:latency] if options[:latency]
61
+ @paused = false
61
62
  end
62
63
 
63
64
  # Start the adapter.
@@ -46,6 +46,8 @@ module Listen
46
46
  def init_worker
47
47
  @worker = FSEvent.new
48
48
  @worker.watch(@directory, :latency => @latency) do |changed_dirs|
49
+ next if @paused
50
+
49
51
  changed_dirs.map! { |path| path.sub /\/$/, '' }
50
52
  @callback.call(changed_dirs, {})
51
53
  end
@@ -57,6 +57,8 @@ module Listen
57
57
  def init_worker
58
58
  @worker = INotify::Notifier.new
59
59
  @worker.watch(@directory, *EVENTS.map(&:to_sym)) do |event|
60
+ next if @paused
61
+
60
62
  unless event.name == "" # Event on root directory
61
63
  @changed_dirs << File.dirname(event.absolute_name)
62
64
  end
@@ -68,6 +70,7 @@ module Listen
68
70
  def poll_changed_dirs
69
71
  until @stop
70
72
  sleep(@latency)
73
+
71
74
  next if @changed_dirs.empty?
72
75
  changed_dirs = @changed_dirs.to_a
73
76
  @changed_dirs.clear
@@ -37,6 +37,8 @@ module Listen
37
37
  #
38
38
  def poll
39
39
  until @stop
40
+ sleep 0.1 && next if @paused
41
+
40
42
  start = Time.now.to_f
41
43
  @callback.call([@directory], :recursive => true)
42
44
  nap_time = @latency - (Time.now.to_f - start)
@@ -50,6 +50,8 @@ module Listen
50
50
  def init_worker
51
51
  @worker = FChange::Notifier.new
52
52
  @worker.watch(@directory, :all_events, :recursive) do |event|
53
+ next if @paused
54
+
53
55
  @changed_dirs << File.expand_path(event.watcher.path)
54
56
  end
55
57
  end
@@ -9,7 +9,7 @@ require 'listen/adapters/windows'
9
9
 
10
10
  module Listen
11
11
  class Listener
12
- attr_accessor :directory, :ignored_paths, :file_filters, :sha1_checksums, :paths, :paused
12
+ attr_accessor :directory, :ignored_paths, :file_filters, :sha1_checksums, :paths, :adapter, :paused
13
13
 
14
14
  # Default paths that gets ignored by the listener
15
15
  DEFAULT_IGNORED_PATHS = %w[.bundle .git .DS_Store log tmp vendor]
@@ -55,35 +55,28 @@ module Listen
55
55
  # Stop the adapter.
56
56
  #
57
57
  def stop
58
- if @paused
59
- @paused = false
60
- else
61
- @adapter.stop
62
- end
58
+ @adapter.stop
63
59
  end
64
60
 
65
- # Stop the adapter and wait
61
+ # Pause the adapter
66
62
  #
67
63
  def pause
68
- @paused = true
69
- @adapter.stop
70
- sleep 0.1 while @paused
64
+ @adapter.paused = true
71
65
  end
72
66
 
73
- # UnPause and re-initialize @paths and start the adapter
67
+ # Re-initialize @paths and unpause the adapter
74
68
  #
75
69
  def unpause
76
- @paused = false
77
70
  init_paths
78
- @adapter.start
71
+ @adapter.paused = false
79
72
  end
80
-
81
- # Is this listener paused
73
+
74
+ # Is adapter paused
82
75
  #
83
- # @return [Boolean] listener paused status
76
+ # @return [Boolean] adapter paused status
84
77
  #
85
78
  def paused?
86
- @paused == true
79
+ !@adapter.nil? && @adapter.paused == true
87
80
  end
88
81
 
89
82
  # Add ignored path to the listener.
@@ -1,3 +1,3 @@
1
1
  module Listen
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: listen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-04 00:00:00.000000000 Z
12
+ date: 2012-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rb-fsevent
16
- requirement: &70305954323260 !ruby/object:Gem::Requirement
16
+ requirement: &70344951028040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.9.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70305954323260
24
+ version_requirements: *70344951028040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rb-inotify
27
- requirement: &70305954322620 !ruby/object:Gem::Requirement
27
+ requirement: &70344951027580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.8.8
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70305954322620
35
+ version_requirements: *70344951027580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rb-fchange
38
- requirement: &70305954322080 !ruby/object:Gem::Requirement
38
+ requirement: &70344951027120 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.0.5
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70305954322080
46
+ version_requirements: *70344951027120
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &70305954321620 !ruby/object:Gem::Requirement
49
+ requirement: &70344951026740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70305954321620
57
+ version_requirements: *70344951026740
58
58
  description: The Listen gem listens to file modifications and notifies you about the
59
59
  changes. Works everywhere!
60
60
  email: