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 +1 -1
- data/lib/rb-inotify.rb +1 -1
- data/lib/rb-inotify/event.rb +5 -0
- data/lib/rb-inotify/notifier.rb +21 -1
- data/rb-inotify.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/lib/rb-inotify.rb
CHANGED
data/lib/rb-inotify/event.rb
CHANGED
@@ -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
|
data/lib/rb-inotify/notifier.rb
CHANGED
@@ -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