Sha256: 2e0d491af3cc56c17afe5ee6ec5bd5671d1be350080e99ffb5871eeaf803809f

Contents?: true

Size: 1.03 KB

Versions: 20

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require 'license_finder/package_utils/possible_license_file'

module LicenseFinder
  class LicenseFiles
    CANDIDATE_FILE_NAMES = %w[License Licence COPYING README].freeze
    CANDIDATE_PATH_WILDCARD = "*{#{CANDIDATE_FILE_NAMES.join(',')}}*"

    def self.find(install_path, options = {})
      new(install_path).find(options)
    end

    def initialize(install_path)
      @install_path = install_path ? Pathname(install_path) : nil
    end

    def find(options = {})
      paths_of_candidate_files
        .map { |path| PossibleLicenseFile.new(path, options) }
        .reject { |file| file.license.nil? }
    end

    private

    attr_reader :install_path

    def paths_of_candidate_files
      candidate_files_and_dirs
        .flat_map { |path| path.directory? ? path.children : path }
        .reject(&:directory?)
        .uniq
    end

    def candidate_files_and_dirs
      return [] if install_path.nil?

      Pathname.glob(install_path.join('**', CANDIDATE_PATH_WILDCARD), File::FNM_CASEFOLD)
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
license_finder-6.15.0 lib/license_finder/package_utils/license_files.rb
gitlab-license_finder-6.14.2.1 lib/license_finder/package_utils/license_files.rb
license_finder-6.14.2 lib/license_finder/package_utils/license_files.rb
license_finder-6.14.1 lib/license_finder/package_utils/license_files.rb
license_finder-6.13.0 lib/license_finder/package_utils/license_files.rb
license_finder-6.12.2 lib/license_finder/package_utils/license_files.rb
license_finder-6.12.1 lib/license_finder/package_utils/license_files.rb
license_finder-6.12.0 lib/license_finder/package_utils/license_files.rb
license_finder-6.11.0 lib/license_finder/package_utils/license_files.rb
license_finder-6.10.1 lib/license_finder/package_utils/license_files.rb
license_finder-6.10.0 lib/license_finder/package_utils/license_files.rb
license_finder-6.9.0 lib/license_finder/package_utils/license_files.rb
license_finder-6.8.2 lib/license_finder/package_utils/license_files.rb
license_finder-6.8.1 lib/license_finder/package_utils/license_files.rb
license_finder-6.8.0 lib/license_finder/package_utils/license_files.rb
license_finder-6.7.0 lib/license_finder/package_utils/license_files.rb
license_finder-6.6.2 lib/license_finder/package_utils/license_files.rb
license_finder-6.6.1 lib/license_finder/package_utils/license_files.rb
license_finder-6.6.0 lib/license_finder/package_utils/license_files.rb
license_finder-6.5.0 lib/license_finder/package_utils/license_files.rb