Module: NeocitiesRed::Services::Common::Exclusions
- Defined in:
- lib/neocities_red/services/common/exclusions.rb
Overview
Builds normalized exclusion lists from user-provided paths.
Given a list of file or directory paths, expands them into all
contained files and normalizes them relative to a base path.
This is used by Site::Pusher to apply
the --exclude option.
Class Method Summary collapse
-
.build(excluded_entries, base_path: nil) ⇒ Array<String>
Builds a normalized exclusion list from the given entries.
Class Method Details
.build(excluded_entries, base_path: nil) ⇒ Array<String>
Builds a normalized exclusion list from the given entries.
For each entry:
- If it is a file, includes it directly
- If it is a directory, recursively includes all contained files
- Non-existent entries are silently skipped
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/neocities_red/services/common/exclusions.rb', line 34 def build(excluded_entries, base_path: nil) base = base_path && Pathname.new(base_path). excluded_entries.flat_map do |entry| target = base ? Pathname.new(entry). : Pathname.new(entry).cleanpath next [] unless target.exist? paths = if ::File.file?(target) [target.to_s] elsif ::File.directory?(target) Dir.glob(::File.join(target, "**", "*"), ::File::FNM_DOTMATCH) else [] end paths.push(target.to_s) if ::File.directory?(target) paths.map { |path| normalize(path, base) }.uniq end end |