Sha256: 67e2c8d6b4a75f007157334acd057ab9d1b1e8e08d720af8eca043e97ae6fecd

Contents?: true

Size: 1.04 KB

Versions: 23

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'license_finder/package_utils/possible_license_file'

module LicenseFinder
  class LicenseFiles
    CANDIDATE_FILE_NAMES = %w[LICENSE License LICENCE Licence COPYING README Readme 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))
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
license_finder-6.4.0 lib/license_finder/package_utils/license_files.rb
license_finder-6.3.0 lib/license_finder/package_utils/license_files.rb
license_finder-6.2.0 lib/license_finder/package_utils/license_files.rb
license_finder-6.1.2 lib/license_finder/package_utils/license_files.rb
license_finder-6.1.0 lib/license_finder/package_utils/license_files.rb
license_finder-6.0.0 lib/license_finder/package_utils/license_files.rb
license_finder-5.11.1 lib/license_finder/package_utils/license_files.rb
license_finder-5.11.0 lib/license_finder/package_utils/license_files.rb
license_finder-5.10.2 lib/license_finder/package_utils/license_files.rb
license_finder-5.10.1 lib/license_finder/package_utils/license_files.rb
license_finder-5.10.0 lib/license_finder/package_utils/license_files.rb
license_finder-5.9.2 lib/license_finder/package_utils/license_files.rb
license_finder-5.9.1 lib/license_finder/package_utils/license_files.rb
license_finder-5.9.0 lib/license_finder/package_utils/license_files.rb
license_finder-5.8.0 lib/license_finder/package_utils/license_files.rb
license_finder-5.7.1 lib/license_finder/package_utils/license_files.rb
license_finder-5.7.0 lib/license_finder/package_utils/license_files.rb
license_finder-5.6.2 lib/license_finder/package_utils/license_files.rb
license_finder-5.6.1 lib/license_finder/package_utils/license_files.rb
license_finder-5.6.0 lib/license_finder/package_utils/license_files.rb