Class: RubyLint::FileList

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-lint/file_list.rb

Overview

The FileList class acts as a small wrapper around Dir.glob and is mainly used to turn a list of filenames/directory names into a list of just file names (excluding ones that don’t exist).

Instance Method Summary collapse

Instance Method Details

#glob_files(directory) ⇒ Array

Returns a list of Ruby files in the given directory. This list includes deeply nested files.

Returns:

  • (Array)


39
40
41
# File 'lib/ruby-lint/file_list.rb', line 39

def glob_files(directory)
  return Dir.glob(File.join(directory, '**/*.rb'))
end

#process(files) ⇒ Array

Parameters:

  • files (Array)

Returns:

  • (Array)

Raises:

  • (Errno::ENOENT)

    Raised if a file or directory does not exist.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby-lint/file_list.rb', line 13

def process(files)
  existing = []

  files.each do |file|
    file = File.expand_path(file)

    if File.file?(file)
      existing << file

    elsif File.directory?(file)
      existing = existing | glob_files(file)

    else
      raise Errno::ENOENT, file
    end
  end

  return existing
end