Sha256: 74730a2bb5da63b1ad41ab654cae2931fb841ff7020fe3741851cc8fbbdeb960

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

require 'pathname'

module DirUtils
  SHEBANG_REGEX = /\A#!.*/

  attr_accessor :files_first_line

  def self.file_first_line(file)
    File.open(file){ |f| f.readline }.gsub(/(.*)\n/, '\1')
  rescue
  end

  def self.file_has_shebang?(file)
    file_first_line(file) =~ SHEBANG_REGEX
  end

  def self.files_same_first_line?(file1, file2)
    file_first_line(file1) == file_first_line(file2)
  end

  def self.file_permissions(file)
    sprintf("%o", File.stat(file).mode)
  end

  def self.gem_bin_file?(file)
    file =~ /(\A|.*\/)bin\/.*/
  end

  ##
  # Returns a unique list of directories and top level files
  # out of an array of files

  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

  def self.remove_subdirs(dirs)
    dirs.dup.sort_by(&:length).reverse.each do |dir|
      dirs.delete_if{ |d| d =~ /#{dir}\/.+/ }
    end
    dirs
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gem-compare-0.0.3 lib/rubygems/comparator/dir_utils.rb