Sha256: cbee31ed427df1da62df6fd6635afec327a581899cc0935e24976d7b5168e100

Contents?: true

Size: 1.7 KB

Versions: 8

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

module LicenseFinder
  class DecisionApplier
    def initialize(options)
      @decisions = options.fetch(:decisions)
      @all_packages = decisions.packages + options.fetch(:packages)
      @acknowledged = apply_decisions
    end

    attr_reader :acknowledged

    def unapproved
      acknowledged.reject(&:approved?)
    end

    def blacklisted
      acknowledged.select(&:blacklisted?)
    end

    def any_packages?
      all_packages.any?
    end

    private

    attr_reader :decisions, :all_packages

    def apply_decisions
      all_packages
        .map { |package| with_decided_licenses(package) }
        .map { |package| with_approval(package) }
        .map { |package| with_homepage(package) }
        .reject { |package| ignored?(package) }
    end

    def ignored?(package)
      decisions.ignored?(package.name) ||
        (package.groups.any? && package.groups.all? { |group| decisions.ignored_group?(group) })
    end

    def with_decided_licenses(package)
      decisions.licenses_of(package.name).each do |license|
        package.decide_on_license license
      end
      package
    end

    def with_homepage(package)
      homepage = decisions.homepage_of(package.name)
      package.homepage = homepage if homepage
      package
    end

    def with_approval(package)
      if package.licenses.all? { |license| decisions.blacklisted?(license) }
        package.blacklisted!
      elsif decisions.approved?(package.name, package.version)
        package.approved_manually!(decisions.approval_of(package.name, package.version))
      elsif package.licenses.any? { |license| decisions.whitelisted?(license) }
        package.whitelisted!
      end
      package
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
license_finder-5.11.1 lib/license_finder/decision_applier.rb
license_finder-5.11.0 lib/license_finder/decision_applier.rb
license_finder-5.10.2 lib/license_finder/decision_applier.rb
license_finder-5.10.1 lib/license_finder/decision_applier.rb
license_finder-5.10.0 lib/license_finder/decision_applier.rb
license_finder-5.9.2 lib/license_finder/decision_applier.rb
license_finder-5.9.1 lib/license_finder/decision_applier.rb
license_finder-5.9.0 lib/license_finder/decision_applier.rb