Sha256: 1a55aeb13dd5d97bf96588198d59015f754167e1f383d31a2e4d39139c013eda

Contents?: true

Size: 972 Bytes

Versions: 4

Compression:

Stored size: 972 Bytes

Contents

module LicenseFinder
  class LicenseFiles
    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 files
      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

4 entries across 4 versions & 1 rubygems

Version Path
license_finder-0.8.1-java lib/license_finder/license_files.rb
license_finder-0.8.1 lib/license_finder/license_files.rb
license_finder-0.8.0-java lib/license_finder/license_files.rb
license_finder-0.8.0 lib/license_finder/license_files.rb