aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-02-08 10:42:03 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-02-08 10:42:03 -0800
commit1df3b65acccaee908b6a579640f5060094fad8c0 (patch)
treea4bedd51a590990537362d9074ec7086c73e3047
parent9643243204fab063630380f42fcd4b8160044104 (diff)
downloadrails-1df3b65acccaee908b6a579640f5060094fad8c0.tar.gz
rails-1df3b65acccaee908b6a579640f5060094fad8c0.tar.bz2
rails-1df3b65acccaee908b6a579640f5060094fad8c0.zip
use === so that regular expressions are not required
-rw-r--r--activesupport/lib/active_support/file_watcher.rb8
-rw-r--r--activesupport/test/file_watcher_test.rb10
2 files changed, 12 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/file_watcher.rb b/activesupport/lib/active_support/file_watcher.rb
index 046a5a0309..81b4b117c1 100644
--- a/activesupport/lib/active_support/file_watcher.rb
+++ b/activesupport/lib/active_support/file_watcher.rb
@@ -15,21 +15,17 @@ module ActiveSupport
@regex_matchers = {}
end
- def watch(path, &block)
- return watch_regex(path, &block) if path.is_a?(Regexp)
- raise "Paths must be regular expressions. #{path.inspect} is a #{path.class}"
- end
-
def watch_regex(regex, &block)
@regex_matchers[regex] = block
end
+ alias :watch :watch_regex
def trigger(files)
trigger_files = Hash.new { |h,k| h[k] = Hash.new { |h2,k2| h2[k2] = [] } }
files.each do |file, state|
@regex_matchers.each do |regex, block|
- trigger_files[block][state] << file if file =~ regex
+ trigger_files[block][state] << file if regex === file
end
end
diff --git a/activesupport/test/file_watcher_test.rb b/activesupport/test/file_watcher_test.rb
index 54aa9f92f1..3e577df5af 100644
--- a/activesupport/test/file_watcher_test.rb
+++ b/activesupport/test/file_watcher_test.rb
@@ -21,6 +21,16 @@ class FileWatcherTest < ActiveSupport::TestCase
end
end
+ def test_use_triple_equals
+ fw = ActiveSupport::FileWatcher.new
+ called = []
+ fw.watch("some_arbitrary_file.rb") do |file|
+ called << "omg"
+ end
+ fw.trigger(%w{ some_arbitrary_file.rb })
+ assert_equal ['omg'], called
+ end
+
def test_one_change
@backend.trigger("app/assets/main.scss" => :changed)
assert_equal({:changed => ["app/assets/main.scss"]}, @payload.first)