Use set in filewatcher

This commit is contained in:
Ben Hollis 2012-04-17 00:37:44 -07:00
parent 50b797e0be
commit 8178eb5602

View file

@ -1,5 +1,6 @@
require "find" require "find"
require "middleman-core/watcher" require "middleman-core/watcher"
require "set"
# API for watching file change events # API for watching file change events
module Middleman::CoreExtensions::FileWatcher module Middleman::CoreExtensions::FileWatcher
@ -54,7 +55,7 @@ module Middleman::CoreExtensions::FileWatcher
# Initialize api and internal path cache # Initialize api and internal path cache
def initialize def initialize
self.known_paths = [] self.known_paths = Set.new
end end
# Add callback to be run on file change # Add callback to be run on file change
@ -83,7 +84,7 @@ module Middleman::CoreExtensions::FileWatcher
# @return [void] # @return [void]
def did_change(path) def did_change(path)
puts "== File Change: #{path}" if instance.logging? && !::Middleman::Watcher.ignore_list.any? { |r| path.match(r) } puts "== File Change: #{path}" if instance.logging? && !::Middleman::Watcher.ignore_list.any? { |r| path.match(r) }
self.known_paths << path unless self.known_paths.include?(path) self.known_paths << path
self.run_callbacks(path, :changed) self.run_callbacks(path, :changed)
end end
@ -93,7 +94,7 @@ module Middleman::CoreExtensions::FileWatcher
# @return [void] # @return [void]
def did_delete(path) def did_delete(path)
puts "== File Deletion: #{path}" if instance.logging? && !::Middleman::Watcher.ignore_list.any? { |r| path.match(r) } puts "== File Deletion: #{path}" if instance.logging? && !::Middleman::Watcher.ignore_list.any? { |r| path.match(r) }
self.known_paths.delete(path) if self.known_paths.include?(path) self.known_paths.delete(path)
self.run_callbacks(path, :deleted) self.run_callbacks(path, :deleted)
end end