Class: Spoom::FileCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/spoom/file_collector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(allow_extensions: [], allow_mime_types: [], exclude_patterns: []) ⇒ FileCollector

Initialize a new file collector

If ‘allow_extensions` is empty, all files are collected. If `allow_extensions` is an array of extensions, only files with one of these extensions are collected.

If ‘allow_mime_types` is empty, all files are collected. If `allow_mime_types` is an array of mimetypes, files without an extension are collected if their mimetype is in the list. : (?allow_extensions: Array, ?allow_mime_types: Array, ?exclude_patterns: Array) -> void



18
19
20
21
22
23
# File 'lib/spoom/file_collector.rb', line 18

def initialize(allow_extensions: [], allow_mime_types: [], exclude_patterns: [])
  @files = T.let([], T::Array[String])
  @allow_extensions = allow_extensions
  @allow_mime_types = allow_mime_types
  @exclude_patterns = exclude_patterns
end

Instance Attribute Details

#filesObject (readonly)

: Array



7
8
9
# File 'lib/spoom/file_collector.rb', line 7

def files
  @files
end

Instance Method Details

#visit_path(path) ⇒ Object

: (String path) -> void



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/spoom/file_collector.rb', line 31

def visit_path(path)
  path = clean_path(path)

  return if excluded_path?(path)

  if File.file?(path)
    visit_file(path)
  elsif File.directory?(path)
    visit_directory(path)
  else # rubocop:disable Style/EmptyElse
    # Ignore aliases, sockets, etc.
  end
end

#visit_paths(paths) ⇒ Object

: (Array paths) -> void



26
27
28
# File 'lib/spoom/file_collector.rb', line 26

def visit_paths(paths)
  paths.each { |path| visit_path(path) }
end