Sha256: 500f5c0e8c60ddb53604536f8323b1b6a64502755c4811a803e2dcdf8e6d74de
Contents?: true
Size: 1.02 KB
Versions: 2
Compression:
Stored size: 1.02 KB
Contents
module Middleman module WebP class PathnameMatcher # Initializes matcher with given pattern. # # pattern - Pattern to match pathnames against to. May be # string, glob, prog or regex. def initialize(pattern = '**/*') @pattern = pattern end # Checks given file against pattern. # # file - File, Pathname or String def matches?(path) return false if path.nil? send match_method, path end private def match_method @match_method ||= if @pattern.respond_to? :call :matches_proc? elsif @pattern.class == Regexp :matches_re? else :matches_glob? end end def matches_glob?(path) Pathname.new(path).fnmatch?(@pattern) end def matches_re?(path) !@pattern.match(Pathname.new(path).to_s).nil? end def matches_proc?(path) @pattern.call(Pathname.new(path).to_s) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
middleman-webp-0.2.5 | lib/middleman-webp/pathname_matcher.rb |
middleman-webp-0.2.4 | lib/middleman-webp/pathname_matcher.rb |