rb-inotify 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.6.0
data/lib/rb-inotify.rb CHANGED
@@ -13,5 +13,5 @@ module INotify
13
13
  # An array containing the version number of rb-inotify.
14
14
  # The numbers in the array are the major, minor, and patch versions,
15
15
  # respectively.
16
- VERSION = [0, 5, 1]
16
+ VERSION = [0, 6, 0]
17
17
  end
@@ -18,6 +18,11 @@ module INotify
18
18
  #
19
19
  # This pathname is relative to the enclosing directory.
20
20
  # For the absolute pathname, use \{#absolute\_name}.
21
+ # Note that when the `:recursive` flag is passed to {Notifier#watch},
22
+ # events in nested subdirectories will still have a `#name` field
23
+ # relative to their immediately enclosing directory.
24
+ # For example, an event on the file `"foo/bar/baz"`
25
+ # will have name `"baz"`.
21
26
  #
22
27
  # @return [String]
23
28
  attr_reader :name
@@ -79,6 +79,10 @@ module INotify
79
79
  # calling the callback when there are.
80
80
  # This is only activated once \{#process} or \{#run} is called.
81
81
  #
82
+ # **Note that by default, this does not recursively watch subdirectories
83
+ # of the watched directory**.
84
+ # To do so, use the `:recursive` flag.
85
+ #
82
86
  # ## Flags
83
87
  #
84
88
  # `:access`
@@ -151,6 +155,14 @@ module INotify
151
155
  # `:oneshot`
152
156
  # : Only send the event once, then shut down the watcher.
153
157
  #
158
+ # `:recursive`
159
+ # : Recursively watch any subdirectories that are created.
160
+ # Note that this is a feature of rb-inotify,
161
+ # rather than of inotify itself, which can only watch one level of a directory.
162
+ # This means that the {Event#name} field
163
+ # will contain only the basename of the modified file.
164
+ # When using `:recursive`, {Event#absolute_name} should always be used.
165
+ #
154
166
  # @param path [String] The path to the file or directory
155
167
  # @param flags [Array<Symbol>] Which events to watch for
156
168
  # @yield [event] A block that will be called
@@ -162,7 +174,15 @@ module INotify
162
174
  # e.g. if the file isn't found, read access is denied,
163
175
  # or the flags don't contain any events
164
176
  def watch(path, *flags, &callback)
165
- Watcher.new(self, path, *flags, &callback)
177
+ return Watcher.new(self, path, *flags, &callback) unless flags.include?(:recursive)
178
+ Dir[File.join(path, '*/')].each {|d| watch(d, *flags, &callback)}
179
+
180
+ rec_flags = [:create, :moved_to]
181
+ return watch(path, *((flags - [:recursive]) | rec_flags)) do |event|
182
+ callback.call(event) unless (flags & event.flags).empty?
183
+ next if (rec_flags & event.flags).empty? || !event.flags.include?(:isdir)
184
+ watch(event.absolute_name, *flags, &callback)
185
+ end
166
186
  end
167
187
 
168
188
  # Starts the notifier watching for filesystem events.
data/rb-inotify.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rb-inotify}
8
- s.version = "0.5.1"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nathan Weizenbaum"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb-inotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum