Module: FileSmasher

Defined in:
lib/require_smasher/file_smasher.rb

Overview

Find files

Class Method Summary collapse

Class Method Details

.file?(element) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
# File 'lib/require_smasher/file_smasher.rb', line 19

def file?(element)
  file = File.expand_path("./#{element}")
  return true if File.file?(file)
  return false if element.include?('.')

  File.file?("#{file}.rb")
end

.files(directories) ⇒ Object



13
14
15
16
17
# File 'lib/require_smasher/file_smasher.rb', line 13

def files(directories)
  raise DirNotInformedError if directories.empty?

  directories.uniq.map { |directory| FileSmasher.files_by(directory) }.flatten
end

.files_by(directory) ⇒ Object

Raises:



7
8
9
10
11
# File 'lib/require_smasher/file_smasher.rb', line 7

def files_by(directory)
  raise DirNotExistError, "Directory '#{directory}' does not exist" unless Dir.exist?(directory)

  Dir.glob("./#{directory}/**/*.rb")
end