Module: Gem::Comparator::DirUtils
- Defined in:
- lib/rubygems/comparator/dir_utils.rb
Constant Summary collapse
- SHEBANG_REGEX =
/\A#!.*/
Instance Attribute Summary collapse
-
#files_first_line ⇒ Object
Returns the value of attribute files_first_line.
Class Method Summary collapse
-
.dirs_of_files(file_list) ⇒ Object
Returns a unique list of directories and top level files out of an array of files.
- .file_first_line(file) ⇒ Object
- .file_has_shebang?(file) ⇒ Boolean
- .files_same_first_line?(file1, file2) ⇒ Boolean
- .gem_bin_file?(file) ⇒ Boolean
- .remove_subdirs(dirs) ⇒ Object
Instance Attribute Details
#files_first_line ⇒ Object
Returns the value of attribute files_first_line.
7 8 9 |
# File 'lib/rubygems/comparator/dir_utils.rb', line 7 def files_first_line @files_first_line end |
Class Method Details
.dirs_of_files(file_list) ⇒ Object
Returns a unique list of directories and top level files out of an array of files
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rubygems/comparator/dir_utils.rb', line 30 def self.dirs_of_files(file_list) dirs_of_files = [] file_list.each do |file| unless Pathname.new(file).dirname.to_s == '.' dirs_of_files << "#{Pathname.new(file).dirname.to_s}/" else dirs_of_files << file end end dirs_of_files.uniq end |
.file_first_line(file) ⇒ Object
9 10 11 12 |
# File 'lib/rubygems/comparator/dir_utils.rb', line 9 def self.file_first_line(file) File.open(file){ |f| f.readline }.gsub(/(.*)\n/, '\1') rescue end |
.file_has_shebang?(file) ⇒ Boolean
14 15 16 |
# File 'lib/rubygems/comparator/dir_utils.rb', line 14 def self.file_has_shebang?(file) file_first_line(file) =~ SHEBANG_REGEX end |
.files_same_first_line?(file1, file2) ⇒ Boolean
18 19 20 |
# File 'lib/rubygems/comparator/dir_utils.rb', line 18 def self.files_same_first_line?(file1, file2) file_first_line(file1) == file_first_line(file2) end |
.gem_bin_file?(file) ⇒ Boolean
22 23 24 |
# File 'lib/rubygems/comparator/dir_utils.rb', line 22 def self.gem_bin_file?(file) file =~ /(\A|.*\/)bin\/.*/ end |
.remove_subdirs(dirs) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/rubygems/comparator/dir_utils.rb', line 42 def self.remove_subdirs(dirs) dirs.dup.sort_by(&:length).reverse.each do |dir| dirs.delete_if{ |d| d =~ /#{dir}\/.+/ } end dirs end |