From 1df3b65acccaee908b6a579640f5060094fad8c0 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 8 Feb 2011 10:42:03 -0800 Subject: use === so that regular expressions are not required --- activesupport/lib/active_support/file_watcher.rb | 8 ++------ activesupport/test/file_watcher_test.rb | 10 ++++++++++ 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) -- cgit v1.2.3