Fixed implementation of Middleman::Util#path_match, added tests for it

This commit is contained in:
Ben Hollis 2014-06-16 21:43:14 -07:00
parent 8989e27769
commit ad4b441dc3
2 changed files with 45 additions and 4 deletions

View file

@ -96,13 +96,17 @@ module Middleman
# to #match or #call, and returns whether or not the
# given path matches that matcher.
#
# @param matcher A matcher string/regexp/proc/etc
# @param path A path as a string
# @param [String, #match, #call] matcher A matcher String, RegExp, Proc, etc.
# @param [String] path A path as a string
# @return [Boolean] Whether the path matches the matcher
def path_match(matcher, path)
case
!!case
when matcher.is_a?(String)
path.match(matcher)
if matcher.include? '*'
File.fnmatch(matcher, path)
else
path == matcher
end
when matcher.respond_to?(:match)
matcher.match(path)
when matcher.respond_to?(:call)