guard 1.0.3 → 1.1.0.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
data/lib/guard/ui.rb CHANGED
@@ -81,7 +81,7 @@ module Guard
81
81
  # Clear the output.
82
82
  #
83
83
  def clear
84
- system('clear;')
84
+ system('clear;') if ::Guard.options[:clear]
85
85
  end
86
86
 
87
87
  private
data/lib/guard/version.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  module Guard
2
- unless defined? Guard::VERSION
3
- # The current gem version of Guard
4
- VERSION = '1.0.3'
5
- end
2
+ # The current gem version of Guard
3
+ VERSION = '1.1.0.alpha'
6
4
  end
data/lib/guard/watcher.rb CHANGED
@@ -41,6 +41,7 @@ module Guard
41
41
  # @return [Array<Object>] the matched watcher response
42
42
  #
43
43
  def self.match_files(guard, files)
44
+ return [] if files.empty?
44
45
  guard.watchers.inject([]) do |paths, watcher|
45
46
  files.each do |file|
46
47
  if matches = watcher.match(file)
metadata CHANGED
@@ -1,40 +1,40 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
5
- prerelease:
4
+ version: 1.1.0.alpha
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Thibaud Guillaume-Gentil
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-14 00:00:00.000000000 Z
12
+ date: 2012-05-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.14.6
21
+ version: 0.15.2
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.14.6
29
+ version: 0.15.2
30
30
  - !ruby/object:Gem::Dependency
31
- name: ffi
31
+ name: listen
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 0.5.0
37
+ version: 0.4.2
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: 0.5.0
45
+ version: 0.4.2
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: bundler
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: 2.8.0
69
+ version: 2.10.0
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +74,7 @@ dependencies:
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: 2.8.0
77
+ version: 2.10.0
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: guard-rspec
80
80
  requirement: !ruby/object:Gem::Requirement
@@ -82,7 +82,7 @@ dependencies:
82
82
  requirements:
83
83
  - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: 0.6.0
85
+ version: 0.7.0
86
86
  type: :development
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,7 +90,7 @@ dependencies:
90
90
  requirements:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: 0.6.0
93
+ version: 0.7.0
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: yard
96
96
  requirement: !ruby/object:Gem::Requirement
@@ -148,7 +148,6 @@ extensions: []
148
148
  extra_rdoc_files: []
149
149
  files:
150
150
  - bin/fsevent_watch_guard
151
- - bin/fsevent_watch_guard_guard
152
151
  - bin/guard
153
152
  - images/failed.png
154
153
  - images/pending.png
@@ -158,15 +157,11 @@ files:
158
157
  - lib/guard/dsl_describer.rb
159
158
  - lib/guard/group.rb
160
159
  - lib/guard/guard.rb
160
+ - lib/guard/guardfile.rb
161
161
  - lib/guard/hook.rb
162
162
  - lib/guard/interactor.rb
163
163
  - lib/guard/interactors/readline.rb
164
164
  - lib/guard/interactors/simple.rb
165
- - lib/guard/listener.rb
166
- - lib/guard/listeners/darwin.rb
167
- - lib/guard/listeners/linux.rb
168
- - lib/guard/listeners/polling.rb
169
- - lib/guard/listeners/windows.rb
170
165
  - lib/guard/notifier.rb
171
166
  - lib/guard/notifiers/gntp.rb
172
167
  - lib/guard/notifiers/growl.rb
@@ -174,68 +169,12 @@ files:
174
169
  - lib/guard/notifiers/libnotify.rb
175
170
  - lib/guard/notifiers/notifysend.rb
176
171
  - lib/guard/notifiers/rb_notifu.rb
172
+ - lib/guard/runner.rb
177
173
  - lib/guard/templates/Guardfile
178
174
  - lib/guard/ui.rb
179
175
  - lib/guard/version.rb
180
176
  - lib/guard/watcher.rb
181
177
  - lib/guard.rb
182
- - lib/vendor/darwin/bin/fsevent_watch
183
- - lib/vendor/darwin/ext/fsevent_watch/fsevent_watch/cli.c
184
- - lib/vendor/darwin/ext/fsevent_watch/fsevent_watch/cli.h
185
- - lib/vendor/darwin/ext/fsevent_watch/fsevent_watch/common.h
186
- - lib/vendor/darwin/ext/fsevent_watch/fsevent_watch/compat.c
187
- - lib/vendor/darwin/ext/fsevent_watch/fsevent_watch/compat.h
188
- - lib/vendor/darwin/ext/fsevent_watch/fsevent_watch/main.c
189
- - lib/vendor/darwin/ext/fsevent_watch/fsevent_watch/TSICTString.c
190
- - lib/vendor/darwin/ext/fsevent_watch/fsevent_watch/TSICTString.h
191
- - lib/vendor/darwin/ext/fsevent_watch/fsevent_watch.xcodeproj/project.pbxproj
192
- - lib/vendor/darwin/ext/fsevent_watch/Info.plist
193
- - lib/vendor/darwin/ext/fsevent_watch/LICENSE
194
- - lib/vendor/darwin/ext/fsevent_watch/xcconfig/Common.xcconfig
195
- - lib/vendor/darwin/ext/fsevent_watch/xcconfig/Debug.xcconfig
196
- - lib/vendor/darwin/ext/fsevent_watch/xcconfig/fsevent_watch.xcconfig
197
- - lib/vendor/darwin/ext/fsevent_watch/xcconfig/Release.xcconfig
198
- - lib/vendor/darwin/ext/rakefile.rb
199
- - lib/vendor/darwin/ext/rb-fsevent.xcconfig
200
- - lib/vendor/darwin/Gemfile
201
- - lib/vendor/darwin/Guardfile
202
- - lib/vendor/darwin/lib/rb-fsevent/fsevent.rb
203
- - lib/vendor/darwin/lib/rb-fsevent/version.rb
204
- - lib/vendor/darwin/lib/rb-fsevent.rb
205
- - lib/vendor/darwin/LICENSE
206
- - lib/vendor/darwin/Rakefile
207
- - lib/vendor/darwin/rb-fsevent.gemspec
208
- - lib/vendor/darwin/README.rdoc
209
- - lib/vendor/darwin/spec/fixtures/folder1/file1.txt
210
- - lib/vendor/darwin/spec/fixtures/folder1/folder2/file2.txt
211
- - lib/vendor/darwin/spec/rb-fsevent/fsevent_spec.rb
212
- - lib/vendor/darwin/spec/spec_helper.rb
213
- - lib/vendor/linux/lib/rb-inotify/event.rb
214
- - lib/vendor/linux/lib/rb-inotify/native/flags.rb
215
- - lib/vendor/linux/lib/rb-inotify/native.rb
216
- - lib/vendor/linux/lib/rb-inotify/notifier.rb
217
- - lib/vendor/linux/lib/rb-inotify/watcher.rb
218
- - lib/vendor/linux/lib/rb-inotify.rb
219
- - lib/vendor/linux/MIT-LICENSE
220
- - lib/vendor/linux/Rakefile
221
- - lib/vendor/linux/rb-inotify.gemspec
222
- - lib/vendor/linux/README.md
223
- - lib/vendor/linux/VERSION
224
- - lib/vendor/windows/Gemfile
225
- - lib/vendor/windows/lib/rb-fchange/event.rb
226
- - lib/vendor/windows/lib/rb-fchange/native/flags.rb
227
- - lib/vendor/windows/lib/rb-fchange/native.rb
228
- - lib/vendor/windows/lib/rb-fchange/notifier.rb
229
- - lib/vendor/windows/lib/rb-fchange/version.rb
230
- - lib/vendor/windows/lib/rb-fchange/watcher.rb
231
- - lib/vendor/windows/lib/rb-fchange.rb
232
- - lib/vendor/windows/Rakefile
233
- - lib/vendor/windows/rb-fchange.gemspec
234
- - lib/vendor/windows/README.md
235
- - lib/vendor/windows/spec/fixtures/folder1/file1.txt
236
- - lib/vendor/windows/spec/fixtures/folder1/folder2/file2.txt
237
- - lib/vendor/windows/spec/rb-fchange/fchange_spec.rb
238
- - lib/vendor/windows/spec/spec_helper.rb
239
178
  - CHANGELOG.md
240
179
  - LICENSE
241
180
  - man/guard.1
Binary file
@@ -1,376 +0,0 @@
1
- require 'rbconfig'
2
- require 'digest/sha1'
3
-
4
- module Guard
5
-
6
- autoload :Darwin, 'guard/listeners/darwin'
7
- autoload :Linux, 'guard/listeners/linux'
8
- autoload :Windows, 'guard/listeners/windows'
9
- autoload :Polling, 'guard/listeners/polling'
10
-
11
- # The Listener is the base class for all listener
12
- # implementations.
13
- #
14
- # @abstract
15
- #
16
- class Listener
17
-
18
- # Default paths that gets ignored by the listener
19
- DEFAULT_IGNORE_PATHS = %w[. .. .bundle .git log tmp vendor]
20
-
21
- attr_accessor :changed_files
22
- attr_reader :directory, :ignore_paths
23
-
24
- def paused?
25
- @paused
26
- end
27
-
28
- # Select the appropriate listener implementation for the
29
- # current OS and initializes it.
30
- #
31
- # @param [Hash] options the options for the listener
32
- # @option options [String] watchdir the directory to watch
33
- # @return [Guard::Listener] the chosen listener
34
- #
35
- def self.select_and_init(options = {})
36
- watchdir = options && options[:watchdir] && File.expand_path(options[:watchdir])
37
- watchdir = Dir.pwd unless watchdir
38
-
39
- no_vendor = options && options[:no_vendor] ? options[:no_vendor] : false
40
-
41
- if mac? && Darwin.usable?(no_vendor)
42
- Darwin.new(watchdir, options)
43
- elsif linux? && Linux.usable?(no_vendor)
44
- Linux.new(watchdir, options)
45
- elsif windows? && Windows.usable?(no_vendor)
46
- Windows.new(watchdir, options)
47
- else
48
- UI.info 'Using polling (Please help us to support your system better than that).'
49
- Polling.new(watchdir, options)
50
- end
51
- end
52
-
53
- # Initialize the listener.
54
- #
55
- # @param [String] directory the root directory to listen to
56
- # @option options [Boolean] relativize_paths use only relative paths
57
- # @option options [Boolean] watch_all_modifications to enable deleted and moved file listening.
58
- # @option options [Array<String>] ignore_paths the paths to ignore by the listener
59
- #
60
- def initialize(directory = Dir.pwd, options = {})
61
- @sha1_checksums_hash = {}
62
- @file_timestamp_hash = {}
63
- @changed_files = []
64
- @paused = false
65
-
66
- @directory = directory.to_s
67
-
68
- options = options.inject({}) { |h,(k,v)| h[k.to_sym] = v; h }
69
- @relativize_paths = options.fetch(:relativize_paths, true)
70
- @watch_all_modifications = options.fetch(:watch_all_modifications, false)
71
-
72
- @ignore_paths = DEFAULT_IGNORE_PATHS
73
- @ignore_paths |= options[:ignore_paths] if options[:ignore_paths]
74
-
75
- update_last_event
76
- start_reactor
77
- end
78
-
79
- # Start watching the root directory.
80
- #
81
- def start
82
- watch(@directory)
83
- timestamp_files if watch_all_modifications?
84
- end
85
-
86
- # Stop listening for events.
87
- #
88
- def stop
89
- end
90
-
91
- # Pause the listener to ignore change events.
92
- #
93
- def pause
94
- @paused = true
95
- end
96
-
97
- # Unpause the listener to listen again to change events.
98
- #
99
- def run
100
- @paused = false
101
- end
102
-
103
- # Clear the list of changed files.
104
- #
105
- def clear_changed_files
106
- @changed_files.clear
107
- end
108
-
109
- # Store a listener callback.
110
- #
111
- # @param [Block] callback the callback to store
112
- #
113
- def on_change(&callback)
114
- @callback = callback
115
- end
116
-
117
- # Updates the timestamp of the last event.
118
- #
119
- def update_last_event
120
- @last_event = Time.now
121
- end
122
-
123
- # Get the modified files.
124
- #
125
- # If the `:watch_all_modifications` option is true, then moved and
126
- # deleted files are also reported, but prefixed by an exclamation point.
127
- #
128
- # @example Deleted or moved file
129
- # !/home/user/dir/file.rb
130
- #
131
- # @param [Array<String>] dirs the watched directories
132
- # @param [Hash] options the listener options
133
- # @option options [Symbol] all whether to files in sub directories
134
- # @return [Array<String>] paths of files that have been modified
135
- #
136
- def modified_files(dirs, options = {})
137
- last_event = @last_event
138
- files = []
139
-
140
- if watch_all_modifications?
141
- deleted_files = @file_timestamp_hash.collect do |path, ts|
142
- unless File.exists?(path)
143
- @sha1_checksums_hash.delete(path)
144
- @file_timestamp_hash.delete(path)
145
- "!#{path}"
146
- end
147
- end
148
- files.concat(deleted_files.compact)
149
- end
150
- update_last_event
151
- updated_files = potentially_modified_files(dirs, options).select do |path|
152
- file_modified?(path, last_event)
153
- end
154
- files.concat(updated_files)
155
-
156
- relativize_paths(files)
157
- end
158
-
159
- # Register a directory to watch.
160
- # Must be implemented by the subclasses.
161
- #
162
- # @param [String] directory the directory to watch
163
- #
164
- def watch(directory)
165
- raise NotImplementedError, "do whatever you want here, given the directory as only argument"
166
- end
167
-
168
- # Get all files that are in the watched directory.
169
- #
170
- # @return [Array<String>] the list of files
171
- #
172
- def all_files
173
- potentially_modified_files([@directory], :all => true)
174
- end
175
-
176
- # Scopes all given paths to the current directory.
177
- #
178
- # @param [Array<String>] paths the paths to change
179
- # @return [Array<String>] all paths now relative to the current dir
180
- #
181
- def relativize_paths(paths)
182
- return paths unless relativize_paths?
183
- paths.map do |path|
184
- path.gsub(%r{^(!)?#{ @directory }/},'\1')
185
- end
186
- end
187
-
188
- # Use paths relative to the current directory.
189
- #
190
- # @return [Boolean] whether to use relative or absolute paths
191
- #
192
- def relativize_paths?
193
- !!@relativize_paths
194
- end
195
-
196
- # test if the listener should also watch for deleted and
197
- # moved files
198
- #
199
- # @return [Boolean] whether to watch all file modifications or not
200
- #
201
- def watch_all_modifications?
202
- !!@watch_all_modifications
203
- end
204
-
205
- # Populate initial timestamp file hash to watch for deleted or moved files.
206
- #
207
- def timestamp_files
208
- all_files.each { |path| set_file_timestamp_hash(path) }
209
- end
210
-
211
- # Removes the ignored paths from the directory list.
212
- #
213
- # @param [Array<String>] dirs the directory to listen to
214
- # @param [Array<String>] ignore_paths the paths to ignore
215
- # @return children of the passed dirs that are not in the ignore_paths list
216
- #
217
- def exclude_ignored_paths(dirs, ignore_paths = self.ignore_paths)
218
- Dir.glob(dirs.map { |d| "#{d.sub(%r{/+$}, '')}/*" }, File::FNM_DOTMATCH).reject do |path|
219
- ignore_paths.include?(File.basename(path))
220
- end
221
- end
222
-
223
- private
224
-
225
- # Start the listener thread.
226
- #
227
- def start_reactor
228
- return if ENV["GUARD_ENV"] == 'test'
229
-
230
- Thread.new do
231
- loop do
232
- if @changed_files != [] && !@paused
233
- changed_files = @changed_files.dup
234
- clear_changed_files
235
- ::Guard.run_on_change(changed_files)
236
- else
237
- sleep 0.1
238
- end
239
- end
240
- end
241
- end
242
-
243
- # Gets a list of files that are in the modified directories.
244
- #
245
- # @param [Array<String>] dirs the list of directories
246
- # @param [Hash] options the find file option
247
- # @option options [Symbol] all whether to files in sub directories
248
- #
249
- def potentially_modified_files(dirs, options = {})
250
- paths = exclude_ignored_paths(dirs)
251
-
252
- if options[:all]
253
- paths.inject([]) do |array, path|
254
- if File.file?(path)
255
- array << path
256
- else
257
- array += Dir.glob("#{ path }/**/*", File::FNM_DOTMATCH).select { |p| File.file?(p) }
258
- end
259
- array
260
- end
261
- else
262
- paths.select { |path| File.file?(path) }
263
- end
264
- end
265
-
266
- # Test if the file content has changed.
267
- #
268
- # Depending on the filesystem, mtime/ctime is probably only precise to the second, so round
269
- # both values down to the second for the comparison.
270
- #
271
- # ctime is used only on == comparison to always catches Rails 3.1 Assets pipelined on Mac OSX
272
- #
273
- # @param [String] path the file path
274
- # @param [Time] last_event the time of the last event
275
- # @return [Boolean] Whether the file content has changed or not.
276
- #
277
- def file_modified?(path, last_event)
278
- ctime = File.ctime(path).to_i
279
- mtime = File.mtime(path).to_i
280
-
281
- if [mtime, ctime].max == last_event.to_i
282
- file_content_modified?(path)
283
- elsif mtime > last_event.to_i
284
- set_sha1_checksums_hash(path)
285
- set_file_timestamp_hash(path) if watch_all_modifications?
286
- true
287
- elsif watch_all_modifications?
288
- ts = file_timestamp(path)
289
- if ts != @file_timestamp_hash[path]
290
- set_file_timestamp_hash(path, ts)
291
- true
292
- end
293
- else
294
- false
295
- end
296
- rescue
297
- false
298
- end
299
-
300
- # Tests if the file content has been modified by
301
- # comparing the SHA1 checksum.
302
- #
303
- # @param [String] path the file path
304
- #
305
- def file_content_modified?(path)
306
- checksum = sha1_checksum(path)
307
- if @sha1_checksums_hash[path] != checksum
308
- set_sha1_checksums_hash(path, checksum)
309
- true
310
- else
311
- false
312
- end
313
- end
314
-
315
- # Set save a files current timestamp
316
- #
317
- # @param [String] path the file path
318
- # @param [Integer] file_timestamp the files modified timestamp
319
- #
320
- def set_file_timestamp_hash(path, timestamp = nil)
321
- @file_timestamp_hash[path] = timestamp ? timestamp : file_timestamp(path)
322
- end
323
-
324
- # Set the current checksum of a file.
325
- #
326
- # @param [String] path the file path
327
- # @param [String] sha1_checksum the checksum of the file
328
- #
329
- def set_sha1_checksums_hash(path, checksum = nil)
330
- @sha1_checksums_hash[path] = checksum ? checksum : sha1_checksum(path)
331
- end
332
-
333
- # Gets a files modified timestamp
334
- #
335
- # @param [String] path the file path
336
- # @return [Integer] file modified timestamp
337
- #
338
- def file_timestamp(path)
339
- File.mtime(path).to_i
340
- end
341
-
342
- # Calculates the SHA1 checksum of a file.
343
- #
344
- # @param [String] path the path to the file
345
- # @return [String] the SHA1 checksum
346
- #
347
- def sha1_checksum(path)
348
- Digest::SHA1.file(path).to_s
349
- end
350
-
351
- # Test if the OS is Mac OS X.
352
- #
353
- # @return [Boolean] Whether the OS is Mac OS X
354
- #
355
- def self.mac?
356
- RbConfig::CONFIG['target_os'] =~ /darwin/i
357
- end
358
-
359
- # Test if the OS is Linux.
360
- #
361
- # @return [Boolean] Whether the OS is Linux
362
- #
363
- def self.linux?
364
- RbConfig::CONFIG['target_os'] =~ /linux/i
365
- end
366
-
367
- # Test if the OS is Windows.
368
- #
369
- # @return [Boolean] Whether the OS is Windows
370
- #
371
- def self.windows?
372
- RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
373
- end
374
-
375
- end
376
- end