Sha256: eb1a9fee42901b2b6f1e26dbf5f79b1ca04784eea6151b524b58925260f78809

Contents?: true

Size: 979 Bytes

Versions: 12

Compression:

Stored size: 979 Bytes

Contents

module LicenseFinder
  class PossibleLicenseFiles
    LICENSE_FILE_NAMES = %w(LICENSE License Licence COPYING README Readme ReadMe)

    def initialize(install_path)
      @install_path = install_path
    end

    attr_reader :install_path

    def find
      paths_for_license_files.map do |path|
        get_file_for_path(path)
      end
    end

    def paths_for_license_files
      find_matching_files.map do |path|
        File.directory?(path) ? paths_for_files_in_license_directory(path) : path
      end.flatten.uniq
    end

    def find_matching_files
      Dir.glob(File.join(install_path, '**', "*{#{LICENSE_FILE_NAMES.join(',')}}*"))
    end

    def paths_for_files_in_license_directory(path)
      entries_in_directory = Dir::entries(path).reject { |p| p.match(/^(\.){1,2}$/) }
      entries_in_directory.map { |entry_name| File.join(path, entry_name) }
    end

    def get_file_for_path(path)
      PossibleLicenseFile.new(install_path, path)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
license_finder-0.9.4-java lib/license_finder/possible_license_files.rb
license_finder-0.9.4 lib/license_finder/possible_license_files.rb
license_finder-0.9.3-java lib/license_finder/possible_license_files.rb
license_finder-0.9.3 lib/license_finder/possible_license_files.rb
license_finder-0.9.2-java lib/license_finder/possible_license_files.rb
license_finder-0.9.2 lib/license_finder/possible_license_files.rb
license_finder-0.9.1-java lib/license_finder/possible_license_files.rb
license_finder-0.9.1 lib/license_finder/possible_license_files.rb
license_finder-0.9.0-java lib/license_finder/possible_license_files.rb
license_finder-0.9.0 lib/license_finder/possible_license_files.rb
license_finder-0.8.2-java lib/license_finder/possible_license_files.rb
license_finder-0.8.2 lib/license_finder/possible_license_files.rb