licensure 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5887811c86a3c1c6981aa5ec6c9b1efd5ac9b3752a93eb1d588c6d62acb9d704
4
- data.tar.gz: 53baba973dcbc133f942fbf251b30bc380a745b473aa235bddd06cc929eb0098
3
+ metadata.gz: 2805125ca2b8cc001a334352f8b5799fd95687e28f3f452a8b9ddd3363e1ca6a
4
+ data.tar.gz: a3cbb3378e66fb24a4239c7d317c39c2c35ccb5765900b862ebf4eb9edb879d8
5
5
  SHA512:
6
- metadata.gz: fd784c7b336d63fc34f34e229757877a8fd9efabc392dd66930da6241fbf7be4a2e19f450eaaed47f4930b4cc8dc9994fd1320c510cf83736de2650729d06dca
7
- data.tar.gz: ebded542cf8af7901a0e59a4ab1c92e8f3a4e7531167a99022a7ce8c3a409208cd53617f225b630c2f36d3f0aba0bb565f23b793cfe03bba964595496ad5b778
6
+ metadata.gz: d495b2ee905388c8683376c37b94cba58c7519228b434851dd2f1c4f3b009ab2f43df8479fc3a15cabe6620b5f4de1e983c77eeb36a309a0dd2e693cbd1c005e
7
+ data.tar.gz: f7a3e6aa8ea488b1173a7a9767d0ad23b1c1f05edb79c880ba607a8411f4a5263d302c0a24fe69f5b1b32f66e2bc33c8f5df8d0a2d18e1e396f3da312e4faf0c
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Licensure
1
+ # Licensure [![Gem Version](https://badge.fury.io/rb/licensure.svg)](https://badge.fury.io/rb/licensure) [![Ruby](https://github.com/ydah/licensure/actions/workflows/main.yml/badge.svg)](https://github.com/ydah/licensure/actions/workflows/main.yml)
2
2
 
3
3
  Licensure is a RubyGem CLI tool that inspects dependency licenses from `Gemfile.lock` and checks them against a configurable allow list.
4
4
 
@@ -52,7 +52,15 @@ module Licensure
52
52
  # @param licenses [Array<String>]
53
53
  # @return [Array<String>]
54
54
  def disallowed_licenses(licenses)
55
- licenses.reject { |license| @configuration.allowed_licenses.include?(license) }
55
+ licenses.reject { |license| allowed_license?(license) }
56
+ end
57
+
58
+ # @param license [String]
59
+ # @return [Boolean]
60
+ def allowed_license?(license)
61
+ @configuration.allowed_licenses.any? do |allowed_license|
62
+ LicenseMatcher.match?(allowed_license, license)
63
+ end
56
64
  end
57
65
  end
58
66
  end
@@ -193,26 +193,15 @@ module Licensure
193
193
  # @param key [String, nil]
194
194
  # @return [Array<String>]
195
195
  def canonicalize_licenses(licenses, spdx_id, name, key)
196
- fingerprints = [spdx_id, name, key].filter_map { |value| license_fingerprint(value) }.uniq
196
+ fingerprints = [spdx_id, name, key].filter_map { |value| LicenseMatcher.fingerprint(value) }.uniq
197
197
  return licenses if fingerprints.empty?
198
198
 
199
199
  licenses.map do |license|
200
- fingerprint = license_fingerprint(license)
200
+ fingerprint = LicenseMatcher.fingerprint(license)
201
201
  fingerprints.include?(fingerprint) ? spdx_id : license
202
202
  end.uniq
203
203
  end
204
204
 
205
- # @param value [String, nil]
206
- # @return [String, nil]
207
- def license_fingerprint(value)
208
- fingerprint = value.to_s.downcase
209
- .gsub(/\b(the|license|version)\b/, "")
210
- .gsub(/[^a-z0-9]/, "")
211
- return nil if fingerprint.empty?
212
-
213
- fingerprint
214
- end
215
-
216
205
  # @param name [String]
217
206
  # @param version [String]
218
207
  # @param licenses [Array<String>]
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Licensure
4
+ # Compares license labels with lightweight normalization.
5
+ module LicenseMatcher
6
+ module_function
7
+
8
+ # @param left [String]
9
+ # @param right [String]
10
+ # @return [Boolean]
11
+ def match?(left, right)
12
+ return true if left == right
13
+
14
+ left_fingerprint = fingerprint(left)
15
+ right_fingerprint = fingerprint(right)
16
+ return false unless left_fingerprint && right_fingerprint
17
+
18
+ left_fingerprint == right_fingerprint
19
+ end
20
+
21
+ # @param value [String, nil]
22
+ # @return [String, nil]
23
+ def fingerprint(value)
24
+ normalized = value.to_s.downcase
25
+ .gsub(/\b(the|license|version)\b/, "")
26
+ .gsub(/[^a-z0-9]/, "")
27
+ return nil if normalized.empty?
28
+
29
+ normalized
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Licensure
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/licensure.rb CHANGED
@@ -6,6 +6,7 @@ require_relative "licensure/types"
6
6
  require_relative "licensure/configuration"
7
7
  require_relative "licensure/dependency_resolver"
8
8
  require_relative "licensure/license_fetcher"
9
+ require_relative "licensure/license_matcher"
9
10
  require_relative "licensure/license_checker"
10
11
  require_relative "licensure/formatters/base"
11
12
  require_relative "licensure/formatters/table"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: licensure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yudai Takada
@@ -63,6 +63,7 @@ files:
63
63
  - lib/licensure/formatters/table.rb
64
64
  - lib/licensure/license_checker.rb
65
65
  - lib/licensure/license_fetcher.rb
66
+ - lib/licensure/license_matcher.rb
66
67
  - lib/licensure/types.rb
67
68
  - lib/licensure/version.rb
68
69
  homepage: https://github.com/ydah/licensure