Sha256: 9f2eadd71a25992b5a614aa0f71adc1798596a56db266f1ba3989bb9238b3894

Contents?: true

Size: 1.39 KB

Versions: 46

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

require 'license_finder/package_utils/activation'

module LicenseFinder
  Licensing = Struct.new(:package, :decided_licenses, :licenses_from_spec, :license_files) do
    # Implements the algorithm for choosing the right set of licenses from
    # among the various sources of licenses we know about.  In order of
    # priority, licenses come from decisions, package specs, or package files.
    def activations
      if activations_from_decisions.any? then activations_from_decisions
      elsif activations_from_spec.any?      then activations_from_spec
      elsif activations_from_files.any?     then activations_from_files
      else [default_activation]
      end
    end

    def activations_from_decisions
      @activations_from_decisions ||= decided_licenses
               .map { |license| Activation::FromDecision.new(package, license) }
    end

    def activations_from_spec
      @activations_from_spec ||= licenses_from_spec
               .map { |license| Activation::FromSpec.new(package, license) }
    end

    def activations_from_files
      @activations_from_files ||= license_files
               .group_by(&:license)
               .map { |license, files| Activation::FromFiles.new(package, license, files) }
    end

    def default_activation
      default_license = License.find_by_name nil
      Activation::None.new(package, default_license)
    end
  end
end

Version data entries

46 entries across 46 versions & 2 rubygems

Version Path
license_finder-7.1.0 lib/license_finder/package_utils/licensing.rb
license_finder-7.0.1 lib/license_finder/package_utils/licensing.rb
license_finder-7.0.0 lib/license_finder/package_utils/licensing.rb
license_finder-6.15.0 lib/license_finder/package_utils/licensing.rb
gitlab-license_finder-6.14.2.1 lib/license_finder/package_utils/licensing.rb
license_finder-6.14.2 lib/license_finder/package_utils/licensing.rb
license_finder-6.14.1 lib/license_finder/package_utils/licensing.rb
license_finder-6.13.0 lib/license_finder/package_utils/licensing.rb
license_finder-6.12.2 lib/license_finder/package_utils/licensing.rb
license_finder-6.12.1 lib/license_finder/package_utils/licensing.rb
license_finder-6.12.0 lib/license_finder/package_utils/licensing.rb
license_finder-6.11.0 lib/license_finder/package_utils/licensing.rb
license_finder-6.10.1 lib/license_finder/package_utils/licensing.rb
license_finder-6.10.0 lib/license_finder/package_utils/licensing.rb
license_finder-6.9.0 lib/license_finder/package_utils/licensing.rb
license_finder-6.8.2 lib/license_finder/package_utils/licensing.rb
license_finder-6.8.1 lib/license_finder/package_utils/licensing.rb
license_finder-6.8.0 lib/license_finder/package_utils/licensing.rb
license_finder-6.7.0 lib/license_finder/package_utils/licensing.rb
license_finder-6.6.2 lib/license_finder/package_utils/licensing.rb