Module: FindAndClean
- Included in:
- Fundler
- Defined in:
- lib/fundler/find_and_clean.rb
Instance Method Summary collapse
- #all_files(root = Dir.pwd) ⇒ Object
- #clean_all_filenames(root = Dir.pwd) ⇒ Object
- #get_list ⇒ Object
- #get_pwd ⇒ Object
-
#ruby_files(root = Dir.pwd) ⇒ Array
Finds all Ruby source files under the current or other supplied directory.
Instance Method Details
#all_files(root = Dir.pwd) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/fundler/find_and_clean.rb', line 23 def all_files(root = Dir.pwd) files = Dir.open(root).reject { |file| FileTest.directory? file } files_found = files.select do |file| file !=~ /^\./ end files_found.sort end |
#clean_all_filenames(root = Dir.pwd) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/fundler/find_and_clean.rb', line 31 def clean_all_filenames(root = Dir.pwd) renamed = [] self.all_files(root).each do |file| new_name = file.downcase.gsub(/\s+/, '_') File.rename(file, new_name) renamed << new_name end renamed.count end |
#get_list ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fundler/find_and_clean.rb', line 45 def get_list out = "" all_files.each do |file| out << "- " << File.absolute_path(file) out << " | " << File.atime(file).to_s out << " | " << File.size(file).to_s out << "\n" end puts out end |
#get_pwd ⇒ Object
41 42 43 |
# File 'lib/fundler/find_and_clean.rb', line 41 def get_pwd Dir.pwd end |
#ruby_files(root = Dir.pwd) ⇒ Array
Finds all Ruby source files under the current or other supplied directory. A Ruby source file is defined as a file with the ‘.rb` extension or a file with no extension that has a ruby shebang line as its first line. ruby source files
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fundler/find_and_clean.rb', line 12 def ruby_files(root = Dir.pwd) files = Dir.open(root).reject { |file| FileTest.directory? file } rb_files = [] rb_files << files.select { |file| File.extname(file) == '.rb' } rb_files << files.select do |file| File.extname(file) == '' && File.open(file) { |f| f.readline } =~ /#!.*ruby/ end rb_files.flatten.sort end |