Replace all_files_under with method that doesn't modify in-place

This commit is contained in:
Ben Hollis 2013-05-04 10:56:38 -07:00
parent 2ef3b7e4d9
commit 64878bfc23

View file

@ -136,13 +136,15 @@ module Middleman
# @param paths Some paths string or Pathname # @param paths Some paths string or Pathname
# @return [Array] An array of filenames # @return [Array] An array of filenames
def self.all_files_under(*paths) def self.all_files_under(*paths)
paths.flatten! # when we drop 1.8, replace this with flat_map
paths.map! { |p| Pathname(p) } paths.map do |p|
files = paths.select { |p| p.file? } path = Pathname(p)
paths.select {|p| p.directory? }.each do |dir| if path.directory?
files << all_files_under(dir.children) all_files_under(*path.children)
end elsif path.file?
files.flatten path
end
end.flatten.compact
end end
# Simple shared cache implementation # Simple shared cache implementation