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,34 +0,0 @@
1
- # rb-fchange
2
-
3
- Code is working. But there is still a lot of work.
4
- This is a simple wrapper over the Windows Kernel functions for monitoring the specified directory or subtree.
5
- Tested on:
6
-
7
- - jruby 1.6.1 (ruby-1.8.7-p330) (2011-04-12 85838f6)
8
- - ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-ingw32]
9
- - ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
10
-
11
- Example
12
-
13
- ```ruby
14
- require 'rb-fchange'
15
-
16
- notifier = FChange::Notifier.new
17
- notifier.watch("test", :all_events, :recursive) do |event|
18
- p Time.now.utc
19
- end
20
-
21
- Signal.trap('INT') do
22
- p "Bye bye...",
23
- notifier.stop
24
- abort("\n")
25
- end
26
-
27
- notifier.run
28
- ```
29
-
30
- ## TODO
31
-
32
- - add latency setting with 0.5 default
33
- - rework interface (should more look like rb-fsevent)
34
- - add none-ANSI path support
@@ -1,18 +0,0 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
4
- require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new(:spec)
6
- task :default => :spec
7
-
8
- namespace(:spec) do
9
- desc "Run all specs on multiple ruby versions (requires pik)"
10
- task(:portability) do
11
- %w[187 192 161].each do |version|
12
- system("echo -----------#{version}------------")
13
- system("pik use #{version}")
14
- system("bundle install")
15
- system("rake spec")
16
- end
17
- end
18
- end
@@ -1,14 +0,0 @@
1
- require "rb-fchange/native"
2
- require "rb-fchange/native/flags"
3
- require "rb-fchange/notifier"
4
- require "rb-fchange/watcher"
5
- require "rb-fchange/event"
6
-
7
- # The root module of the library, which is laid out as so:
8
- #
9
- # * {Notifier} -- The main class, where the notifications are set up
10
- # * {Watcher} -- A watcher for a single file or directory
11
- # * {Event} -- An filesystem event notification
12
- module FChange
13
-
14
- end
@@ -1,29 +0,0 @@
1
- module FChange
2
- # An event caused by a change on the filesystem.
3
- # Each {Watcher} can fire many events,
4
- # which are passed to that watcher's callback.
5
- class Event
6
- # The {Watcher} that fired this event.
7
- #
8
- # @return [Watcher]
9
- attr_reader :watcher
10
-
11
- # Creates an event from a string of binary data.
12
- # Differs from {Event.consume} in that it doesn't modify the string.
13
- #
14
- # @private
15
- # @param watcher [Watcher] The {Watcher} that fired the event
16
- def initialize(watcher)
17
- @watcher = watcher
18
- end
19
-
20
- # Calls the callback of the watcher that fired this event,
21
- # passing in the event itself.
22
- #
23
- # @private
24
- def callback!
25
- @watcher.callback!(self)
26
- end
27
-
28
- end
29
- end
@@ -1,45 +0,0 @@
1
- require 'ffi'
2
-
3
- module FChange
4
- # This module contains the low-level foreign-function.
5
- # It's an implementation detail, and not meant for users to deal with.
6
- #
7
- # @private
8
- module Native
9
- extend FFI::Library
10
- ffi_lib 'kernel32'
11
- ffi_convention :stdcall
12
-
13
- # HANDLE FindFirstChangeNotification(
14
- # LPCTSTR lpPathName, // directory name
15
- # BOOL bWatchSubtree, // monitoring option
16
- # DWORD dwNotifyFilter // filter conditions
17
- #);
18
- attach_function :FindFirstChangeNotificationW, [:pointer, :int, :long], :long
19
-
20
- # HANDLE FindFirstChangeNotification(
21
- # LPCTSTR lpPathName, // directory name
22
- # BOOL bWatchSubtree, // monitoring option
23
- # DWORD dwNotifyFilter // filter conditions
24
- #);
25
- attach_function :FindFirstChangeNotificationA, [:pointer, :int, :long], :long
26
-
27
- # BOOL FindNextChangeNotification(
28
- # HANDLE hChangeHandle // handle to change notification
29
- # );
30
- attach_function :FindNextChangeNotification, [:long], :int
31
-
32
- # DAORD WaitForMultipleObjects(
33
- # DWORD nCount, // number of handles in array
34
- # CONST HANDLE *lpHandles, // object-handle array
35
- # BOOL bWaitAll, // wait option
36
- # DWORD dwMilliseconds // time-out interval
37
- # );
38
- attach_function :WaitForMultipleObjects, [:long, :pointer, :int, :long], :long
39
-
40
- # BOOL FindCloseChangeNotification(
41
- # HANDLE hChangeHandle
42
- # );
43
- attach_function :FindCloseChangeNotification, [:long], :int
44
- end
45
- end
@@ -1,78 +0,0 @@
1
- module FChange
2
- module Native
3
- # A module containing all the flags to be passed to {Notifier#watch}.
4
- # @see http://msdn.microsoft.com/en-us/library/aa364417(v=VS.85).aspx
5
- #
6
- # @private
7
- module Flags
8
-
9
- # Any file name change in the watched directory or subtree causes a change
10
- # notification wait operation to return. Changes include renaming,
11
- # creating, or deleting a file name.
12
- FILE_NOTIFY_CHANGE_FILE_NAME = 0x00000001
13
-
14
- # Any directory-name change in the watched directory or subtree causes a
15
- # change notification wait operation to return. Changes include creating
16
- # or deleting a directory.
17
- FILE_NOTIFY_CHANGE_DIR_NAME = 0x00000002
18
-
19
- # Any attribute change in the watched directory or subtree causes a change
20
- # notification wait operation to return.
21
- FILE_NOTIFY_CHANGE_ATTRIBUTES = 0x00000004
22
-
23
- # Any file-size change in the watched directory or subtree causes a change
24
- # notification wait operation to return. The operating system detects a
25
- # change in file size only when the file is written to the disk.
26
- # For operating systems that use extensive caching, detection occurs only
27
- # when the cache is sufficiently flushed.
28
- FILE_NOTIFY_CHANGE_SIZE = 0x00000008
29
-
30
- # Any change to the last write-time of files in the watched directory or
31
- # subtree causes a change notification wait operation to return.
32
- # The operating system detects a change to the last write-time only when
33
- # the file is written to the disk. For operating systems that use
34
- # extensive caching, detection occurs only when the cache is sufficiently
35
- # flushed
36
- FILE_NOTIFY_CHANGE_LAST_WRITE = 0x00000010
37
-
38
- # Any change to the last access time of files in the watched directory or
39
- # subtree causes a change notification wait operation to return.
40
- FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x00000020
41
-
42
- # Any change to the creation time of files in the watched directory or
43
- # subtree causes a change notification wait operation to return.
44
- FILE_NOTIFY_CHANGE_CREATION = 0x00000040
45
-
46
- # Any security-descriptor change in the watched directory or subtree
47
- # causes a change notification wait operation to return.
48
- FILE_NOTIFY_CHANGE_SECURITY = 0x00000100
49
-
50
- FILE_NOTIFY_CHANGE_ALL_EVENTS = (
51
- FILE_NOTIFY_CHANGE_DIR_NAME |
52
- FILE_NOTIFY_CHANGE_FILE_NAME |
53
- FILE_NOTIFY_CHANGE_LAST_WRITE
54
- )
55
-
56
- # Converts a list of flags to the bitmask that the C API expects.
57
- #
58
- # @param flags [Array<Symbol>]
59
- # @return [Fixnum]
60
- def self.to_mask(flags)
61
- flags.map {|flag| const_get("FILE_NOTIFY_CHANGE_#{flag.to_s.upcase}")}.
62
- inject(0) {|mask, flag| mask | flag}
63
- end
64
-
65
- # Converts a bitmask from the C API into a list of flags.
66
- #
67
- # @param mask [Fixnum]
68
- # @return [Array<Symbol>]
69
- def self.from_mask(mask)
70
- constants.map {|c| c.to_s}.select do |c|
71
- next false unless c =~ /^FILE_NOTIFY_CHANGE_/
72
- const_get(c) & mask != 0
73
- end.map {|c| c.sub("FILE_NOTIFY_CHANGE_", "").downcase.to_sym} - [:all_events]
74
- end
75
-
76
- end
77
- end
78
- end
@@ -1,149 +0,0 @@
1
- module FChange
2
- # Notifier wraps a single instance of FChange.
3
- # It's possible to have more than one instance,
4
- # but usually unnecessary.
5
- #
6
- # @example
7
- # # Create the notifier
8
- # notifier = FChange::Notifier.new
9
- #
10
- # # Run this callback whenever the file path/to/foo.txt is read
11
- # notifier.watch("path/to/foo/", :all_events) do
12
- # puts "foo was accessed!"
13
- # end
14
- #
15
- # # Nothing happens until you run the notifier!
16
- # notifier.run
17
- class Notifier
18
-
19
- #
20
- INFINITE = 0xFFFFFFFF
21
-
22
- #
23
- WAIT_OBJECT_0 = 0x00000000
24
-
25
- # A hash from {Watcher} ids to the instances themselves.
26
- #
27
- # @private
28
- # @return [{Fixnum => Watcher}]
29
- attr_reader :watchers
30
-
31
- attr_reader :dwChangeHandles
32
- attr_reader :lp_dwChangeHandles
33
-
34
- # Creates a new {Notifier}.
35
- #
36
- # @return [Notifier]
37
- def initialize
38
- @watchers = {}
39
- @dwChangeHandles = []
40
- @lp_dwChangeHandles = 0
41
- end
42
-
43
- # Adds a new {Watcher} to the queue.
44
- def add_watcher(watcher)
45
-
46
- @watchers[watcher.id] = watcher
47
-
48
- @dwChangeHandles.push watcher.id
49
-
50
- # Pack event handles into newly created storage area
51
- # to be used for Win32 call
52
- @lp_dwChangeHandles = dwChangeHandles.pack("L" * dwChangeHandles.count)
53
-
54
- end
55
-
56
- # Watches a file or directory for changes,
57
- # calling the callback when there are.
58
- # This is only activated once \{#process} or \{#run} is called.
59
- #
60
- # **Note that by default, this does not recursively watch subdirectories
61
- # of the watched directory**.
62
- # To do so, use the `:recursive` flag.
63
- #
64
- # `:recursive`
65
- # : Recursively watch any subdirectories that are created.
66
- #
67
- # @param path [String] The path to the file or directory
68
- # @param flags [Array<Symbol>] Which events to watch for
69
- # @yield [event] A block that will be called
70
- # whenever one of the specified events occur
71
- # @yieldparam event [Event] The Event object containing information
72
- # about the event that occured
73
- # @return [Watcher] A Watcher set up to watch this path for these events
74
- # @raise [SystemCallError] if the file or directory can't be watched,
75
- # e.g. if the file isn't found, read access is denied,
76
- # or the flags don't contain any events
77
- def watch(path, *flags, &callback)
78
- recursive = flags.include?(:recursive)
79
- #:latency = 0.5
80
- flags = flags - [:recursive]
81
- if flags.empty?
82
- @flags = [:all_events]
83
- else
84
- @flags = flags.freeze
85
- end
86
- Watcher.new(self, path, recursive, *@flags, &callback)
87
- end
88
-
89
- # Starts the notifier watching for filesystem events.
90
- # Blocks until \{#stop} is called.
91
- #
92
- # @see #process
93
- def run
94
- @stop = false
95
- process until @stop
96
- end
97
-
98
- # Stop watching for filesystem events.
99
- # That is, if we're in a \{#run} loop,
100
- # exit out as soon as we finish handling the events.
101
- def stop
102
- @stop = true
103
- end
104
-
105
- # Blocks until there are one or more filesystem events
106
- # that this notifier has watchers registered for.
107
- # Once there are events, the appropriate callbacks are called
108
- # and this function returns.
109
- #
110
- # @see #run
111
- def process
112
- read_events.each {|event| event.callback!}
113
- end
114
-
115
- # Blocks until there are one or more filesystem events
116
- # that this notifier has watchers registered for.
117
- # Once there are events, returns their {Event} objects.
118
- #
119
- # @private
120
- def read_events
121
-
122
- # can return WAIT_TIMEOUT = 0x00000102
123
- dwWaitStatus = Native.WaitForMultipleObjects(@dwChangeHandles.count,
124
- @lp_dwChangeHandles, 0, 500)
125
-
126
- events = []
127
-
128
- # this call blocks all threads completely.
129
- @dwChangeHandles.each_index do |index|
130
- if dwWaitStatus == WAIT_OBJECT_0 + index
131
-
132
- ev = Event.new(@watchers[@dwChangeHandles[index]])
133
- events << ev
134
-
135
- r = Native.FindNextChangeNotification(@dwChangeHandles[index])
136
- if r == 0
137
- raise SystemCallError.new("Failed to watch", r)
138
- end
139
- end
140
- end
141
- events
142
- end
143
-
144
- def close
145
-
146
- end
147
-
148
- end
149
- end
@@ -1,3 +0,0 @@
1
- module FChange
2
- VERSION = "0.0.5"
3
- end
@@ -1,99 +0,0 @@
1
- require 'pathname'
2
-
3
- module FChange
4
- # Watchers monitor a single path for changes,
5
- # specified by {FChange::Notifier#watch event flags}.
6
- # A watcher is usually created via \{Notifier#watch}.
7
- #
8
- # One {Notifier} may have many {Watcher}s.
9
- # The Notifier actually takes care of the checking for events,
10
- # via \{Notifier#run #run} or \{Notifier#process #process}.
11
- # The main purpose of having Watcher objects
12
- # is to be able to disable them using \{#close}.
13
- class Watcher
14
- # The {Notifier} that this Watcher belongs to.
15
- #
16
- # @return [Notifier]
17
- attr_reader :notifier
18
-
19
- # The path that this Watcher is watching.
20
- #
21
- # @return [String]
22
- attr_reader :path
23
-
24
- # The {FChange::Notifier#watch flags}
25
- # specifying the events that this Watcher is watching for,
26
- # and potentially some options as well.
27
- #
28
- # @return [Array<Symbol>]
29
- attr_reader :flags
30
-
31
- # The id for this Watcher.
32
- # Used to retrieve this Watcher from {Notifier#watchers}.
33
- #
34
- # @private
35
- # @return [Fixnum]
36
- attr_reader :id
37
-
38
- #
39
- # @private
40
- # @return [Boolean]
41
- attr_reader :recursive
42
-
43
- # Calls this Watcher's callback with the given {Event}.
44
- #
45
- # @private
46
- # @param event [Event]
47
- def callback!(event)
48
- @callback[event]
49
- end
50
-
51
- # Disables this Watcher, so that it doesn't fire any more events.
52
- #
53
- # @raise [SystemCallError] if the watch fails to be disabled for some reason
54
- def close
55
- r = Native.FindCloseChangeNotification(@id)
56
- #@notifier.remove_watcher(self)
57
- return if r == 0
58
- raise SystemCallError.new("Failed to stop watching #{@path.inspect}", r)
59
- end
60
-
61
- # see http://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx
62
- def normalize_path(path)
63
- if(path.size > 256)
64
- path = "\\\\?\\" + Pathname.new(path).realpath.to_s
65
- end
66
- # require 'rchardet'
67
- # require 'iconv'
68
- # cd = CharDet.detect(path)
69
- # encoding = cd['encoding']
70
- # converter = Iconv.new("UTF-16LE", encoding)
71
- # converter.iconv(path)
72
- # path.encode!("UTF-16LE")
73
- end
74
-
75
- # Creates a new {Watcher}.
76
- #
77
- # @private
78
- # @see Notifier#watch
79
- def initialize(notifier, path, recursive, *flags, &callback)
80
- @notifier = notifier
81
- @callback = callback || proc {}
82
- @path = path
83
- @flags = flags
84
- @recursive = recursive ? 1 : 0
85
-
86
- @id = Native.FindFirstChangeNotificationA(path, @recursive,
87
- Native::Flags.to_mask(flags));
88
- # @id = Native.FindFirstChangeNotificationW(normalize_path(path), @recursive,
89
- # Native::Flags.to_mask(flags));
90
-
91
- unless @id < 0
92
- @notifier.add_watcher(self)
93
- return
94
- end
95
-
96
- raise SystemCallError.new("Failed to watch #{path.inspect}", @id)
97
- end
98
- end
99
- end