formula: convert license array to hash
This commit is contained in:
parent
6cde37247d
commit
6eb07d70f0
@ -2232,7 +2232,14 @@ class Formula
|
|||||||
# <pre>license all_of: ["MIT", "GPL-2.0-only"]</pre>
|
# <pre>license all_of: ["MIT", "GPL-2.0-only"]</pre>
|
||||||
# <pre>license "GPL-2.0-only" => { with: "LLVM-exception" }</pre>
|
# <pre>license "GPL-2.0-only" => { with: "LLVM-exception" }</pre>
|
||||||
# <pre>license :public_domain</pre>
|
# <pre>license :public_domain</pre>
|
||||||
attr_rw :license
|
def license(args = nil)
|
||||||
|
if args.nil?
|
||||||
|
@licenses
|
||||||
|
else
|
||||||
|
args = { any_of: args } if args.is_a? Array
|
||||||
|
@licenses = args
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# @!attribute [w] homepage
|
# @!attribute [w] homepage
|
||||||
# The homepage for the software. Used by users to get more information
|
# The homepage for the software. Used by users to get more information
|
||||||
|
|||||||
@ -167,10 +167,6 @@ describe SPDX do
|
|||||||
expect(described_class.license_expression_to_string(any_of: ["MIT", "EPL-1.0+"])).to eq "MIT or EPL-1.0+"
|
expect(described_class.license_expression_to_string(any_of: ["MIT", "EPL-1.0+"])).to eq "MIT or EPL-1.0+"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "treats array as any_of:" do
|
|
||||||
expect(described_class.license_expression_to_string(["MIT", "EPL-1.0+"])).to eq "MIT or EPL-1.0+"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns license and exception" do
|
it "returns license and exception" do
|
||||||
license_expression = { "MIT" => { with: "LLVM-exception" } }
|
license_expression = { "MIT" => { with: "LLVM-exception" } }
|
||||||
expect(described_class.license_expression_to_string(license_expression)).to eq "MIT with LLVM-exception"
|
expect(described_class.license_expression_to_string(license_expression)).to eq "MIT with LLVM-exception"
|
||||||
@ -237,7 +233,6 @@ describe SPDX do
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let(:any_of_license) { { any_of: ["MIT", "0BSD"] } }
|
let(:any_of_license) { { any_of: ["MIT", "0BSD"] } }
|
||||||
let(:license_array) { ["MIT", "0BSD"] }
|
|
||||||
let(:all_of_license) { { all_of: ["MIT", "0BSD"] } }
|
let(:all_of_license) { { all_of: ["MIT", "0BSD"] } }
|
||||||
let(:nested_licenses) {
|
let(:nested_licenses) {
|
||||||
{
|
{
|
||||||
@ -278,14 +273,6 @@ describe SPDX do
|
|||||||
expect(described_class.licenses_forbid_installation?(any_of_license, multiple_forbidden)).to eq true
|
expect(described_class.licenses_forbid_installation?(any_of_license, multiple_forbidden)).to eq true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "allows installation when one of the array licenses is allowed" do
|
|
||||||
expect(described_class.licenses_forbid_installation?(license_array, mit_forbidden)).to eq false
|
|
||||||
end
|
|
||||||
|
|
||||||
it "forbids installation when none of the array licenses are allowed" do
|
|
||||||
expect(described_class.licenses_forbid_installation?(license_array, multiple_forbidden)).to eq true
|
|
||||||
end
|
|
||||||
|
|
||||||
it "forbids installation when one of the all_of licenses is allowed" do
|
it "forbids installation when one of the all_of licenses is allowed" do
|
||||||
expect(described_class.licenses_forbid_installation?(all_of_license, mit_forbidden)).to eq true
|
expect(described_class.licenses_forbid_installation?(all_of_license, mit_forbidden)).to eq true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -83,8 +83,7 @@ module SPDX
|
|||||||
license_expression
|
license_expression
|
||||||
when :public_domain
|
when :public_domain
|
||||||
"Public Domain"
|
"Public Domain"
|
||||||
when Hash, Array
|
when Hash
|
||||||
license_expression = { any_of: license_expression } if license_expression.is_a? Array
|
|
||||||
expressions = []
|
expressions = []
|
||||||
|
|
||||||
if license_expression.keys.length == 1
|
if license_expression.keys.length == 1
|
||||||
@ -135,8 +134,7 @@ module SPDX
|
|||||||
case license_expression
|
case license_expression
|
||||||
when String, Symbol
|
when String, Symbol
|
||||||
forbidden_licenses_include? license_expression.to_s, forbidden_licenses
|
forbidden_licenses_include? license_expression.to_s, forbidden_licenses
|
||||||
when Hash, Array
|
when Hash
|
||||||
license_expression = { any_of: license_expression } if license_expression.is_a? Array
|
|
||||||
key = license_expression.keys.first
|
key = license_expression.keys.first
|
||||||
case key
|
case key
|
||||||
when :any_of
|
when :any_of
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user