guard 1.0.3 → 1.1.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/CHANGELOG.md +0 -6
  2. data/README.md +38 -30
  3. data/lib/guard.rb +158 -285
  4. data/lib/guard/cli.rb +16 -2
  5. data/lib/guard/dsl.rb +41 -20
  6. data/lib/guard/dsl_describer.rb +1 -1
  7. data/lib/guard/group.rb +1 -1
  8. data/lib/guard/guard.rb +39 -5
  9. data/lib/guard/guardfile.rb +70 -0
  10. data/lib/guard/runner.rb +179 -0
  11. data/lib/guard/ui.rb +1 -1
  12. data/lib/guard/version.rb +2 -4
  13. data/lib/guard/watcher.rb +1 -0
  14. metadata +16 -77
  15. data/bin/fsevent_watch_guard_guard +0 -0
  16. data/lib/guard/listener.rb +0 -376
  17. data/lib/guard/listeners/darwin.rb +0 -62
  18. data/lib/guard/listeners/linux.rb +0 -93
  19. data/lib/guard/listeners/polling.rb +0 -55
  20. data/lib/guard/listeners/windows.rb +0 -63
  21. data/lib/vendor/darwin/Gemfile +0 -6
  22. data/lib/vendor/darwin/Guardfile +0 -8
  23. data/lib/vendor/darwin/LICENSE +0 -20
  24. data/lib/vendor/darwin/README.rdoc +0 -255
  25. data/lib/vendor/darwin/Rakefile +0 -21
  26. data/lib/vendor/darwin/bin/fsevent_watch +0 -0
  27. data/lib/vendor/darwin/ext/fsevent_watch/Info.plist +0 -38
  28. data/lib/vendor/darwin/ext/fsevent_watch/LICENSE +0 -21
  29. data/lib/vendor/darwin/ext/fsevent_watch/fsevent_watch.xcodeproj/project.pbxproj +0 -254
  30. data/lib/vendor/darwin/ext/fsevent_watch/fsevent_watch/TSICTString.c +0 -394
  31. data/lib/vendor/darwin/ext/fsevent_watch/fsevent_watch/TSICTString.h +0 -74
  32. data/lib/vendor/darwin/ext/fsevent_watch/fsevent_watch/cli.c +0 -160
  33. data/lib/vendor/darwin/ext/fsevent_watch/fsevent_watch/cli.h +0 -45
  34. data/lib/vendor/darwin/ext/fsevent_watch/fsevent_watch/common.h +0 -34
  35. data/lib/vendor/darwin/ext/fsevent_watch/fsevent_watch/compat.c +0 -20
  36. data/lib/vendor/darwin/ext/fsevent_watch/fsevent_watch/compat.h +0 -40
  37. data/lib/vendor/darwin/ext/fsevent_watch/fsevent_watch/main.c +0 -509
  38. data/lib/vendor/darwin/ext/fsevent_watch/xcconfig/Common.xcconfig +0 -82
  39. data/lib/vendor/darwin/ext/fsevent_watch/xcconfig/Debug.xcconfig +0 -19
  40. data/lib/vendor/darwin/ext/fsevent_watch/xcconfig/Release.xcconfig +0 -23
  41. data/lib/vendor/darwin/ext/fsevent_watch/xcconfig/fsevent_watch.xcconfig +0 -17
  42. data/lib/vendor/darwin/ext/rakefile.rb +0 -47
  43. data/lib/vendor/darwin/ext/rb-fsevent.xcconfig +0 -33
  44. data/lib/vendor/darwin/lib/rb-fsevent.rb +0 -2
  45. data/lib/vendor/darwin/lib/rb-fsevent/fsevent.rb +0 -111
  46. data/lib/vendor/darwin/lib/rb-fsevent/version.rb +0 -3
  47. data/lib/vendor/darwin/rb-fsevent.gemspec +0 -25
  48. data/lib/vendor/darwin/spec/fixtures/folder1/file1.txt +0 -0
  49. data/lib/vendor/darwin/spec/fixtures/folder1/folder2/file2.txt +0 -0
  50. data/lib/vendor/darwin/spec/rb-fsevent/fsevent_spec.rb +0 -88
  51. data/lib/vendor/darwin/spec/spec_helper.rb +0 -23
  52. data/lib/vendor/linux/MIT-LICENSE +0 -20
  53. data/lib/vendor/linux/README.md +0 -66
  54. data/lib/vendor/linux/Rakefile +0 -54
  55. data/lib/vendor/linux/VERSION +0 -1
  56. data/lib/vendor/linux/lib/rb-inotify.rb +0 -17
  57. data/lib/vendor/linux/lib/rb-inotify/event.rb +0 -139
  58. data/lib/vendor/linux/lib/rb-inotify/native.rb +0 -31
  59. data/lib/vendor/linux/lib/rb-inotify/native/flags.rb +0 -89
  60. data/lib/vendor/linux/lib/rb-inotify/notifier.rb +0 -308
  61. data/lib/vendor/linux/lib/rb-inotify/watcher.rb +0 -83
  62. data/lib/vendor/linux/rb-inotify.gemspec +0 -53
  63. data/lib/vendor/windows/Gemfile +0 -4
  64. data/lib/vendor/windows/README.md +0 -34
  65. data/lib/vendor/windows/Rakefile +0 -18
  66. data/lib/vendor/windows/lib/rb-fchange.rb +0 -14
  67. data/lib/vendor/windows/lib/rb-fchange/event.rb +0 -29
  68. data/lib/vendor/windows/lib/rb-fchange/native.rb +0 -45
  69. data/lib/vendor/windows/lib/rb-fchange/native/flags.rb +0 -78
  70. data/lib/vendor/windows/lib/rb-fchange/notifier.rb +0 -149
  71. data/lib/vendor/windows/lib/rb-fchange/version.rb +0 -3
  72. data/lib/vendor/windows/lib/rb-fchange/watcher.rb +0 -99
  73. data/lib/vendor/windows/rb-fchange.gemspec +0 -34
  74. data/lib/vendor/windows/spec/fixtures/folder1/file1.txt +0 -0
  75. data/lib/vendor/windows/spec/fixtures/folder1/folder2/file2.txt +0 -0
  76. data/lib/vendor/windows/spec/rb-fchange/fchange_spec.rb +0 -119
  77. data/lib/vendor/windows/spec/spec_helper.rb +0 -21
@@ -1,308 +0,0 @@
1
- module INotify
2
- # Notifier wraps a single instance of inotify.
3
- # It's possible to have more than one instance,
4
- # but usually unnecessary.
5
- #
6
- # @example
7
- # # Create the notifier
8
- # notifier = INotify::Notifier.new
9
- #
10
- # # Run this callback whenever the file path/to/foo.txt is read
11
- # notifier.watch("path/to/foo.txt", :access) do
12
- # puts "Foo.txt was accessed!"
13
- # end
14
- #
15
- # # Watch for any file in the directory being deleted
16
- # # or moved out of the directory.
17
- # notifier.watch("path/to/directory", :delete, :moved_from) do |event|
18
- # # The #name field of the event object contains the name of the affected file
19
- # puts "#{event.name} is no longer in the directory!"
20
- # end
21
- #
22
- # # Nothing happens until you run the notifier!
23
- # notifier.run
24
- class Notifier
25
- # A list of directories that should never be recursively watched.
26
- #
27
- # * Files in `/dev/fd` sometimes register as directories, but are not enumerable.
28
- RECURSIVE_BLACKLIST = %w[/dev/fd]
29
-
30
- # A hash from {Watcher} ids to the instances themselves.
31
- #
32
- # @private
33
- # @return [{Fixnum => Watcher}]
34
- attr_reader :watchers
35
-
36
- # The underlying file descriptor for this notifier.
37
- # This is a valid OS file descriptor, and can be used as such
38
- # (except under JRuby -- see \{#to\_io}).
39
- #
40
- # @return [Fixnum]
41
- attr_reader :fd
42
-
43
- # @return [Boolean] Whether or not this Ruby implementation supports
44
- # wrapping the native file descriptor in a Ruby IO wrapper.
45
- def self.supports_ruby_io?
46
- RUBY_PLATFORM !~ /java/
47
- end
48
-
49
- # Creates a new {Notifier}.
50
- #
51
- # @return [Notifier]
52
- # @raise [SystemCallError] if inotify failed to initialize for some reason
53
- def initialize
54
- @fd = Native.inotify_init
55
- @watchers = {}
56
- return unless @fd < 0
57
-
58
- raise SystemCallError.new(
59
- "Failed to initialize inotify" +
60
- case FFI.errno
61
- when Errno::EMFILE::Errno; ": the user limit on the total number of inotify instances has been reached."
62
- when Errno::ENFILE::Errno; ": the system limit on the total number of file descriptors has been reached."
63
- when Errno::ENOMEM::Errno; ": insufficient kernel memory is available."
64
- else; ""
65
- end,
66
- FFI.errno)
67
- end
68
-
69
- # Returns a Ruby IO object wrapping the underlying file descriptor.
70
- # Since this file descriptor is fully functional (except under JRuby),
71
- # this IO object can be used in any way a Ruby-created IO object can.
72
- # This includes passing it to functions like `#select`.
73
- #
74
- # Note that this always returns the same IO object.
75
- # Creating lots of IO objects for the same file descriptor
76
- # can cause some odd problems.
77
- #
78
- # **This is not supported under JRuby**.
79
- # JRuby currently doesn't use native file descriptors for the IO object,
80
- # so we can't use this file descriptor as a stand-in.
81
- #
82
- # @return [IO] An IO object wrapping the file descriptor
83
- # @raise [NotImplementedError] if this is being called in JRuby
84
- def to_io
85
- unless self.class.supports_ruby_io?
86
- raise NotImplementedError.new("INotify::Notifier#to_io is not supported under JRuby")
87
- end
88
- @io ||= IO.new(@fd)
89
- end
90
-
91
- # Watches a file or directory for changes,
92
- # calling the callback when there are.
93
- # This is only activated once \{#process} or \{#run} is called.
94
- #
95
- # **Note that by default, this does not recursively watch subdirectories
96
- # of the watched directory**.
97
- # To do so, use the `:recursive` flag.
98
- #
99
- # ## Flags
100
- #
101
- # `:access`
102
- # : A file is accessed (that is, read).
103
- #
104
- # `:attrib`
105
- # : A file's metadata is changed (e.g. permissions, timestamps, etc).
106
- #
107
- # `:close_write`
108
- # : A file that was opened for writing is closed.
109
- #
110
- # `:close_nowrite`
111
- # : A file that was not opened for writing is closed.
112
- #
113
- # `:modify`
114
- # : A file is modified.
115
- #
116
- # `:open`
117
- # : A file is opened.
118
- #
119
- # ### Directory-Specific Flags
120
- #
121
- # These flags only apply when a directory is being watched.
122
- #
123
- # `:moved_from`
124
- # : A file is moved out of the watched directory.
125
- #
126
- # `:moved_to`
127
- # : A file is moved into the watched directory.
128
- #
129
- # `:create`
130
- # : A file is created in the watched directory.
131
- #
132
- # `:delete`
133
- # : A file is deleted in the watched directory.
134
- #
135
- # `:delete_self`
136
- # : The watched file or directory itself is deleted.
137
- #
138
- # `:move_self`
139
- # : The watched file or directory itself is moved.
140
- #
141
- # ### Helper Flags
142
- #
143
- # These flags are just combinations of the flags above.
144
- #
145
- # `:close`
146
- # : Either `:close_write` or `:close_nowrite` is activated.
147
- #
148
- # `:move`
149
- # : Either `:moved_from` or `:moved_to` is activated.
150
- #
151
- # `:all_events`
152
- # : Any event above is activated.
153
- #
154
- # ### Options Flags
155
- #
156
- # These flags don't actually specify events.
157
- # Instead, they specify options for the watcher.
158
- #
159
- # `:onlydir`
160
- # : Only watch the path if it's a directory.
161
- #
162
- # `:dont_follow`
163
- # : Don't follow symlinks.
164
- #
165
- # `:mask_add`
166
- # : Add these flags to the pre-existing flags for this path.
167
- #
168
- # `:oneshot`
169
- # : Only send the event once, then shut down the watcher.
170
- #
171
- # `:recursive`
172
- # : Recursively watch any subdirectories that are created.
173
- # Note that this is a feature of rb-inotify,
174
- # rather than of inotify itself, which can only watch one level of a directory.
175
- # This means that the {Event#name} field
176
- # will contain only the basename of the modified file.
177
- # When using `:recursive`, {Event#absolute_name} should always be used.
178
- #
179
- # @param path [String] The path to the file or directory
180
- # @param flags [Array<Symbol>] Which events to watch for
181
- # @yield [event] A block that will be called
182
- # whenever one of the specified events occur
183
- # @yieldparam event [Event] The Event object containing information
184
- # about the event that occured
185
- # @return [Watcher] A Watcher set up to watch this path for these events
186
- # @raise [SystemCallError] if the file or directory can't be watched,
187
- # e.g. if the file isn't found, read access is denied,
188
- # or the flags don't contain any events
189
- def watch(path, *flags, &callback)
190
- return Watcher.new(self, path, *flags, &callback) unless flags.include?(:recursive)
191
-
192
- Dir.glob(File.join(path, '*'), File::FNM_DOTMATCH).each do |d|
193
- binary_d = d.respond_to?(:force_encoding) ? d.dup.force_encoding('BINARY') : d
194
- next if binary_d =~ /\/\.\.?$/ # Current or parent directory
195
- watch(d, *flags, &callback) if !RECURSIVE_BLACKLIST.include?(d) && File.directory?(d)
196
- end
197
-
198
- rec_flags = [:create, :moved_to]
199
- return watch(path, *((flags - [:recursive]) | rec_flags)) do |event|
200
- callback.call(event) if flags.include?(:all_events) || !(flags & event.flags).empty?
201
- next if (rec_flags & event.flags).empty? || !event.flags.include?(:isdir)
202
- begin
203
- watch(event.absolute_name, *flags, &callback)
204
- rescue Errno::ENOENT
205
- # If the file has been deleted since the glob was run, we don't want to error out.
206
- end
207
- end
208
- end
209
-
210
- # Starts the notifier watching for filesystem events.
211
- # Blocks until \{#stop} is called.
212
- #
213
- # @see #process
214
- def run
215
- @stop = false
216
- process until @stop
217
- end
218
-
219
- # Stop watching for filesystem events.
220
- # That is, if we're in a \{#run} loop,
221
- # exit out as soon as we finish handling the events.
222
- def stop
223
- @stop = true
224
- end
225
-
226
- # Blocks until there are one or more filesystem events
227
- # that this notifier has watchers registered for.
228
- # Once there are events, the appropriate callbacks are called
229
- # and this function returns.
230
- #
231
- # @see #run
232
- def process
233
- read_events.each {|event| event.callback!}
234
- end
235
-
236
- # Close the notifier.
237
- #
238
- # @raise [SystemCallError] if closing the underlying file descriptor fails.
239
- def close
240
- return if Native.close(@fd) == 0
241
-
242
- raise SystemCallError.new("Failed to properly close inotify socket" +
243
- case FFI.errno
244
- when Errno::EBADF::Errno; ": invalid or closed file descriptior"
245
- when Errno::EIO::Errno; ": an I/O error occured"
246
- end,
247
- FFI.errno)
248
- end
249
-
250
- private
251
-
252
- # Blocks until there are one or more filesystem events
253
- # that this notifier has watchers registered for.
254
- # Once there are events, returns their {Event} objects.
255
- def read_events
256
- size = 64 * Native::Event.size
257
- tries = 1
258
-
259
- begin
260
- data = readpartial(size)
261
- rescue SystemCallError => er
262
- # EINVAL means that there's more data to be read
263
- # than will fit in the buffer size
264
- raise er unless er.errno == Errno::EINVAL::Errno || tries == 5
265
- size *= 2
266
- tries += 1
267
- retry
268
- end
269
-
270
- events = []
271
- cookies = {}
272
- while ev = Event.consume(data, self)
273
- events << ev
274
- next if ev.cookie == 0
275
- cookies[ev.cookie] ||= []
276
- cookies[ev.cookie] << ev
277
- end
278
- cookies.each {|c, evs| evs.each {|ev| ev.related.replace(evs - [ev]).freeze}}
279
- events
280
- end
281
-
282
- # Same as IO#readpartial, or as close as we need.
283
- def readpartial(size)
284
- # Use Ruby's readpartial if possible, to avoid blocking other threads.
285
- return to_io.readpartial(size) if self.class.supports_ruby_io?
286
-
287
- tries = 0
288
- begin
289
- tries += 1
290
- buffer = FFI::MemoryPointer.new(:char, size)
291
- size_read = Native.read(fd, buffer, size)
292
- return buffer.read_string(size_read) if size_read >= 0
293
- end while FFI.errno == Errno::EINTR::Errno && tries <= 5
294
-
295
- raise SystemCallError.new("Error reading inotify events" +
296
- case FFI.errno
297
- when Errno::EAGAIN::Errno; ": no data available for non-blocking I/O"
298
- when Errno::EBADF::Errno; ": invalid or closed file descriptor"
299
- when Errno::EFAULT::Errno; ": invalid buffer"
300
- when Errno::EINVAL::Errno; ": invalid file descriptor"
301
- when Errno::EIO::Errno; ": I/O error"
302
- when Errno::EISDIR::Errno; ": file descriptor is a directory"
303
- else; ""
304
- end,
305
- FFI.errno)
306
- end
307
- end
308
- end
@@ -1,83 +0,0 @@
1
- module INotify
2
- # Watchers monitor a single path for changes,
3
- # specified by {INotify::Notifier#watch event flags}.
4
- # A watcher is usually created via \{Notifier#watch}.
5
- #
6
- # One {Notifier} may have many {Watcher}s.
7
- # The Notifier actually takes care of the checking for events,
8
- # via \{Notifier#run #run} or \{Notifier#process #process}.
9
- # The main purpose of having Watcher objects
10
- # is to be able to disable them using \{#close}.
11
- class Watcher
12
- # The {Notifier} that this Watcher belongs to.
13
- #
14
- # @return [Notifier]
15
- attr_reader :notifier
16
-
17
- # The path that this Watcher is watching.
18
- #
19
- # @return [String]
20
- attr_reader :path
21
-
22
- # The {INotify::Notifier#watch flags}
23
- # specifying the events that this Watcher is watching for,
24
- # and potentially some options as well.
25
- #
26
- # @return [Array<Symbol>]
27
- attr_reader :flags
28
-
29
- # The id for this Watcher.
30
- # Used to retrieve this Watcher from {Notifier#watchers}.
31
- #
32
- # @private
33
- # @return [Fixnum]
34
- attr_reader :id
35
-
36
- # Calls this Watcher's callback with the given {Event}.
37
- #
38
- # @private
39
- # @param event [Event]
40
- def callback!(event)
41
- @callback[event]
42
- end
43
-
44
- # Disables this Watcher, so that it doesn't fire any more events.
45
- #
46
- # @raise [SystemCallError] if the watch fails to be disabled for some reason
47
- def close
48
- return if Native.inotify_rm_watch(@notifier.fd, @id) == 0
49
- raise SystemCallError.new("Failed to stop watching #{path.inspect}", FFI.errno)
50
- end
51
-
52
- # Creates a new {Watcher}.
53
- #
54
- # @private
55
- # @see Notifier#watch
56
- def initialize(notifier, path, *flags, &callback)
57
- @notifier = notifier
58
- @callback = callback || proc {}
59
- @path = path
60
- @flags = flags.freeze
61
- @id = Native.inotify_add_watch(@notifier.fd, path.dup,
62
- Native::Flags.to_mask(flags))
63
-
64
- unless @id < 0
65
- @notifier.watchers[@id] = self
66
- return
67
- end
68
-
69
- raise SystemCallError.new(
70
- "Failed to watch #{path.inspect}" +
71
- case FFI.errno
72
- when Errno::EACCES::Errno; ": read access to the given file is not permitted."
73
- when Errno::EBADF::Errno; ": the given file descriptor is not valid."
74
- when Errno::EFAULT::Errno; ": path points outside of the process's accessible address space."
75
- when Errno::EINVAL::Errno; ": the given event mask contains no legal events; or fd is not an inotify file descriptor."
76
- when Errno::ENOMEM::Errno; ": insufficient kernel memory was available."
77
- when Errno::ENOSPC::Errno; ": The user limit on the total number of inotify watches was reached or the kernel failed to allocate a needed resource."
78
- else; ""
79
- end,
80
- FFI.errno)
81
- end
82
- end
83
- end
@@ -1,53 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{rb-inotify}
8
- s.version = "0.8.8"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Nathan Weizenbaum"]
12
- s.date = %q{2011-09-27}
13
- s.description = %q{A Ruby wrapper for Linux's inotify, using FFI}
14
- s.email = %q{nex342@gmail.com}
15
- s.extra_rdoc_files = [
16
- "README.md"
17
- ]
18
- s.files = [
19
- ".yardopts",
20
- "MIT-LICENSE",
21
- "README.md",
22
- "Rakefile",
23
- "VERSION",
24
- "lib/rb-inotify.rb",
25
- "lib/rb-inotify/event.rb",
26
- "lib/rb-inotify/native.rb",
27
- "lib/rb-inotify/native/flags.rb",
28
- "lib/rb-inotify/notifier.rb",
29
- "lib/rb-inotify/watcher.rb",
30
- "rb-inotify.gemspec"
31
- ]
32
- s.homepage = %q{http://github.com/nex3/rb-inotify}
33
- s.require_paths = ["lib"]
34
- s.rubygems_version = %q{1.3.7}
35
- s.summary = %q{A Ruby wrapper for Linux's inotify, using FFI}
36
-
37
- if s.respond_to? :specification_version then
38
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
39
- s.specification_version = 3
40
-
41
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
- s.add_runtime_dependency(%q<ffi>, [">= 0.5.0"])
43
- s.add_development_dependency(%q<yard>, [">= 0.4.0"])
44
- else
45
- s.add_dependency(%q<ffi>, [">= 0.5.0"])
46
- s.add_dependency(%q<yard>, [">= 0.4.0"])
47
- end
48
- else
49
- s.add_dependency(%q<ffi>, [">= 0.5.0"])
50
- s.add_dependency(%q<yard>, [">= 0.4.0"])
51
- end
52
- end
53
-
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in rb-fchange.gemspec
4
- gemspec