Sha256: f587f5de5e2c8141797371e265b1aaa9be4df53066d61954f8b6b75d69d667b4
Contents?: true
Size: 1.8 KB
Versions: 2
Compression:
Stored size: 1.8 KB
Contents
module Bunto class EntryFilter SPECIAL_LEADING_CHARACTERS = ['.', '_', '#'].freeze attr_reader :site def initialize(site, base_directory = nil) @site = site @base_directory = derive_base_directory(@site, base_directory.to_s.dup) end def base_directory @base_directory.to_s end def derive_base_directory(site, base_dir) if base_dir.start_with?(site.source) base_dir[site.source] = "" end base_dir end def relative_to_source(entry) File.join(base_directory, entry) end def filter(entries) entries.reject do |e| unless included?(e) special?(e) || backup?(e) || excluded?(e) || symlink?(e) end end end def included?(entry) glob_include?(site.include, entry) end def special?(entry) SPECIAL_LEADING_CHARACTERS.include?(entry[0..0]) || SPECIAL_LEADING_CHARACTERS.include?(File.basename(entry)[0..0]) end def backup?(entry) entry[-1..-1] == '~' end def excluded?(entry) excluded = glob_include?(site.exclude, relative_to_source(entry)) Bunto.logger.debug "EntryFilter:", "excluded #{relative_to_source(entry)}" if excluded excluded end def symlink?(entry) File.symlink?(entry) && site.safe end def ensure_leading_slash(path) path[0..0] == "/" ? path : "/#{path}" end # Returns true if path matches against any glob pattern. # Look for more detail about glob pattern in method File::fnmatch. def glob_include?(enum, e) entry = ensure_leading_slash(e) enum.any? do |exp| item = ensure_leading_slash(exp) File.fnmatch?(item, entry) || entry.start_with?(item) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
bunto-2.0.0.pre | lib/bunto/entry_filter.rb |
bunto-1.0.0 | lib/bunto/entry_filter.rb |