Add a bit of laziness

This commit is contained in:
Thomas Reynolds 2014-10-15 14:25:06 -05:00
parent f73e89370d
commit 445443cffc
3 changed files with 23 additions and 13 deletions

View file

@ -1,4 +1,5 @@
require 'middleman-core/contracts'
require 'backports/2.0.0/enumerable/lazy'
module Middleman
# The standard "record" that contains information about a file on disk.
@ -168,6 +169,7 @@ module Middleman
Contract Symbol, String, Maybe[Bool] => Maybe[SourceFile]
def find(type, path, glob=false)
watchers
.lazy
.select { |d| d.type == type }
.map { |d| d.find(path, glob) }
.reject { |d| d.nil? }
@ -182,6 +184,7 @@ module Middleman
Contract Symbol, String => Bool
def exists?(type, path)
watchers
.lazy
.select { |d| d.type == type }
.any? { |d| d.exists?(path) }
end