Class: Licensure::LicenseChecker
- Inherits:
-
Object
- Object
- Licensure::LicenseChecker
- Defined in:
- lib/licensure/license_checker.rb
Overview
Checks dependency licenses against configuration rules.
Instance Method Summary collapse
- #check(gem_license_infos) ⇒ Licensure::CheckResult
-
#initialize(configuration:) ⇒ LicenseChecker
constructor
A new instance of LicenseChecker.
Constructor Details
#initialize(configuration:) ⇒ LicenseChecker
Returns a new instance of LicenseChecker.
7 8 9 |
# File 'lib/licensure/license_checker.rb', line 7 def initialize(configuration:) @configuration = configuration end |
Instance Method Details
#check(gem_license_infos) ⇒ Licensure::CheckResult
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/licensure/license_checker.rb', line 13 def check(gem_license_infos) filtered_infos = gem_license_infos.reject do |info| @configuration.ignored_gems.include?(info.name) end violations = [] warnings = [] passed = [] filtered_infos.each do |info| if info.licenses.empty? if @configuration.deny_unknown? warnings << Violation.new(gem_info: info, reason: "License not specified") else passed << info end next end if @configuration.allowed_licenses.empty? passed << info next end disallowed = disallowed_licenses(info.licenses) if disallowed.empty? passed << info next end reason = "Licenses '#{disallowed.join(", ")}' are not in the allowed list" violations << Violation.new(gem_info: info, reason: reason) end CheckResult.new(violations: violations, warnings: warnings, passed: passed) end |