Class: Excavate::Selection

Inherits:
Object
  • Object
show all
Defined in:
lib/excavate/selection.rb

Overview

Picks files from an extracted tree by either an explicit name list or a glob filter. Used by Archive's selective-extraction modes (extract particular files / extract by filter) to share the scaffolding that lives around the matching itself.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_names: nil, filter: nil) ⇒ Selection

Returns a new instance of Selection.



17
18
19
20
# File 'lib/excavate/selection.rb', line 17

def initialize(file_names: nil, filter: nil)
  @file_names = file_names
  @filter = filter
end

Class Method Details

.from_files(names) ⇒ Object



9
10
11
# File 'lib/excavate/selection.rb', line 9

def self.from_files(names)
  new(file_names: names)
end

.from_filter(pattern) ⇒ Object



13
14
15
# File 'lib/excavate/selection.rb', line 13

def self.from_filter(pattern)
  new(filter: pattern)
end

Instance Method Details

#match(paths, base_dir) ⇒ Object

Match paths (absolute file paths produced by an extraction) against this selection. base_dir is the prefix to strip when comparing names; matches are returned as absolute paths from paths. Raises TargetNotFoundError when nothing matches.



26
27
28
29
30
31
32
# File 'lib/excavate/selection.rb', line 26

def match(paths, base_dir)
  if @file_names
    match_explicit(paths, base_dir)
  else
    match_filter(paths, base_dir)
  end
end