Skip to content

Commit

Permalink
use === so that regular expressions are not required
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Feb 8, 2011
1 parent 9643243 commit 1df3b65
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 2 additions & 6 deletions activesupport/lib/active_support/file_watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,17 @@ def initialize
@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

Expand Down
10 changes: 10 additions & 0 deletions activesupport/test/file_watcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ def setup
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)
Expand Down

0 comments on commit 1df3b65

Please sign in to comment.