Class: Metaclean::Discovery

Inherits:
Object
  • Object
show all
Defined in:
lib/metaclean/discovery.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recursive: false) ⇒ Discovery

Returns a new instance of Discovery.



7
8
9
10
11
# File 'lib/metaclean/discovery.rb', line 7

def initialize(recursive: false)
  @recursive = recursive
  @scan_errors = 0
  @guards = {}
end

Instance Attribute Details

#guardsObject (readonly)

Returns the value of attribute guards.



5
6
7
# File 'lib/metaclean/discovery.rb', line 5

def guards
  @guards
end

#scan_errorsObject (readonly)

Returns the value of attribute scan_errors.



5
6
7
# File 'lib/metaclean/discovery.rb', line 5

def scan_errors
  @scan_errors
end

Instance Method Details

#dedupe_by_realpath(paths) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/metaclean/discovery.rb', line 40

def dedupe_by_realpath(paths)
  seen = {}
  paths.each_with_object([]) do |path, result|
    key = safe_realpath(path)
    next if seen[key]

    seen[key] = true
    result << path
  end
end

#expand(paths) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/metaclean/discovery.rb', line 13

def expand(paths)
  @scan_errors = 0
  @guards = {}
  explicit = []
  discovered = []
  paths.each do |path|
    collect_path(path, explicit, discovered)
  end
  discovered.reject! { |file| skip?(file) }
  result = dedupe_by_realpath(explicit + discovered)
  result.select do |file|
    @guards[file] = FileOps.path_guard!(file)
    true
  rescue Error, SystemCallError => e
    scan_failed(file, e)
    false
  end
end

#skip?(file) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/metaclean/discovery.rb', line 32

def skip?(file)
  base = File.basename(file)
  base.start_with?('.') ||
    base.end_with?('.bak') ||
    base.match?(Metaclean::CLEAN_OUTPUT_RE) ||
    base.include?(Metaclean::TMP_MARKER)
end