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.

Examples:

excluded = Exclusions.build(["node_modules", "secret.txt"], base_path: ".")
# => ["node_modules/...", "secret.txt"]

See Also:

Class Method Summary collapse

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

Parameters:

  • excluded_entries (Array<String>)

    file or directory paths to exclude

  • base_path (String, nil) (defaults to: nil)

    base directory for path normalization; when provided, paths are made relative to this base

Returns:

  • (Array<String>)

    flattened, deduplicated list of normalized paths



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).expand_path

  excluded_entries.flat_map do |entry|
    target = base ? Pathname.new(entry).expand_path : 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