mirror of https://github.com/licensee/licensee.git
output human readable name for pseudo licenses
This commit is contained in:
parent
7ca4aff860
commit
e46cd23849
|
@ -16,10 +16,13 @@ module Licensee
|
|||
# Returns an Array of License objects.
|
||||
def all(options = {})
|
||||
@all[options] ||= begin
|
||||
# TODO: Remove in next major version to avoid breaking change
|
||||
options[:pseudo] ||= options[:psuedo]
|
||||
|
||||
options = DEFAULT_OPTIONS.merge(options)
|
||||
output = licenses.dup
|
||||
output.reject!(&:hidden?) unless options[:hidden]
|
||||
output.reject!(&:pseudo_license?) unless options[:psuedo]
|
||||
output.reject!(&:pseudo_license?) unless options[:pseudo]
|
||||
return output if options[:featured].nil?
|
||||
output.select { |l| l.featured? == options[:featured] }
|
||||
end
|
||||
|
@ -32,7 +35,7 @@ module Licensee
|
|||
end
|
||||
|
||||
def find(key, options = {})
|
||||
options = { hidden: true }.merge(options)
|
||||
options = { hidden: true, pseudo: true }.merge(options)
|
||||
keys_licenses(options)[key.downcase]
|
||||
end
|
||||
alias [] find
|
||||
|
@ -40,7 +43,7 @@ module Licensee
|
|||
|
||||
# Given a license title or nickname, fuzzy match the license
|
||||
def find_by_title(title)
|
||||
License.all(hidden: true, psuedo: false).find do |license|
|
||||
License.all(hidden: true, pseudo: false).find do |license|
|
||||
title =~ /\A(the )?#{license.title_regex}( license)?\z/i
|
||||
end
|
||||
end
|
||||
|
@ -82,7 +85,7 @@ module Licensee
|
|||
DEFAULT_OPTIONS = {
|
||||
hidden: false,
|
||||
featured: nil,
|
||||
psuedo: true
|
||||
pseudo: true
|
||||
}.freeze
|
||||
|
||||
ALT_TITLE_REGEX = {
|
||||
|
@ -125,7 +128,8 @@ module Licensee
|
|||
|
||||
# Returns the human-readable license name
|
||||
def name
|
||||
title || spdx_id
|
||||
return title || spdx_id unless pseudo_license?
|
||||
key.tr('-', ' ').capitalize
|
||||
end
|
||||
|
||||
def name_without_version
|
||||
|
|
|
@ -44,6 +44,7 @@ RSpec.describe Licensee::License do
|
|||
it 'includes featured licenses' do
|
||||
expect(licenses).to include(mit)
|
||||
expect(licenses).to_not include(cc_by)
|
||||
expect(licenses).to_not include(other)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -53,7 +54,8 @@ RSpec.describe Licensee::License do
|
|||
it 'includes hidden licenses' do
|
||||
expect(licenses).to include(cc_by)
|
||||
expect(licenses).to include(mit)
|
||||
expect(licenses.count).to eql(license_count)
|
||||
expect(licenses).to_not include(other)
|
||||
expect(licenses.count).to eql(license_count - pseudo_license_count)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -63,6 +65,7 @@ RSpec.describe Licensee::License do
|
|||
it 'includes only featured licenses' do
|
||||
expect(licenses).to include(mit)
|
||||
expect(licenses).to_not include(cc_by)
|
||||
expect(licenses).to_not include(other)
|
||||
expect(licenses.count).to eql(featured_license_count)
|
||||
end
|
||||
end
|
||||
|
@ -73,6 +76,7 @@ RSpec.describe Licensee::License do
|
|||
it 'includes only non-featured licenses' do
|
||||
expect(licenses).to include(unlicense)
|
||||
expect(licenses).to_not include(mit)
|
||||
expect(licenses).to_not include(other)
|
||||
expect(licenses.count).to eql(non_featured_license_count)
|
||||
end
|
||||
|
||||
|
@ -83,18 +87,21 @@ RSpec.describe Licensee::License do
|
|||
expect(licenses).to include(unlicense)
|
||||
expect(licenses).to include(cc_by)
|
||||
expect(licenses).to_not include(mit)
|
||||
expect(licenses.count).to eql(license_count - featured_license_count)
|
||||
expect(licenses).to_not include(other)
|
||||
expected = license_count - featured_license_count
|
||||
expected -= pseudo_license_count
|
||||
expect(licenses.count).to eql(expected)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'psudo licenses' do
|
||||
context 'pseudo licenses' do
|
||||
let(:other) { Licensee::License.find('other') }
|
||||
|
||||
context 'by default' do
|
||||
let(:arguments) { {} }
|
||||
|
||||
it "doesn't include psudo licenses" do
|
||||
it "doesn't include pseudo licenses" do
|
||||
expect(licenses).to_not include(other)
|
||||
end
|
||||
end
|
||||
|
@ -102,13 +109,13 @@ RSpec.describe Licensee::License do
|
|||
context 'with hidden licenses' do
|
||||
let(:arguments) { { hidden: true } }
|
||||
|
||||
it 'includes psudo licenses' do
|
||||
expect(licenses).to include(other)
|
||||
it "doesn't include pseudo licenses" do
|
||||
expect(licenses).to_not include(other)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when explicitly asked' do
|
||||
let(:arguments) { { hidden: true, psuedo: true } }
|
||||
let(:arguments) { { hidden: true, pseudo: true } }
|
||||
|
||||
it 'includes psudo licenses' do
|
||||
expect(licenses).to include(other)
|
||||
|
@ -116,12 +123,30 @@ RSpec.describe Licensee::License do
|
|||
end
|
||||
|
||||
context 'when explicitly excluded' do
|
||||
let(:arguments) { { hidden: true, psuedo: false } }
|
||||
let(:arguments) { { hidden: true, pseudo: false } }
|
||||
|
||||
it "doesn'tincludes psudo licenses" do
|
||||
expect(licenses).to_not include(other)
|
||||
end
|
||||
end
|
||||
|
||||
context 'mispelled' do
|
||||
context 'when explicitly asked' do
|
||||
let(:arguments) { { hidden: true, psuedo: true } }
|
||||
|
||||
it 'includes psudo licenses' do
|
||||
expect(licenses).to include(other)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when explicitly excluded' do
|
||||
let(:arguments) { { hidden: true, psuedo: false } }
|
||||
|
||||
it "doesn'tincludes psudo licenses" do
|
||||
expect(licenses).to_not include(other)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -201,7 +226,8 @@ RSpec.describe Licensee::License do
|
|||
end
|
||||
|
||||
it 'uses the default name when none exists' do
|
||||
expect(other.name).to eql('NOASSERTION')
|
||||
expect(other.name).to eql('Other')
|
||||
expect(no_license.name).to eql('No license')
|
||||
end
|
||||
|
||||
it 'expoeses the nickname' do
|
||||
|
@ -341,7 +367,7 @@ RSpec.describe Licensee::License do
|
|||
end
|
||||
|
||||
context 'License.title_regex' do
|
||||
Licensee::License.all(hidden: true, psuedo: false).each do |license|
|
||||
Licensee::License.all(hidden: true, pseudo: false).each do |license|
|
||||
context "the #{license.title} license" do
|
||||
%i[title nickname key].each do |variation|
|
||||
next if license.send(variation).nil?
|
||||
|
@ -451,7 +477,7 @@ RSpec.describe Licensee::License do
|
|||
end
|
||||
|
||||
context 'source regex' do
|
||||
Licensee::License.all(hidden: true, psuedo: false).each do |license|
|
||||
Licensee::License.all(hidden: true, pseudo: false).each do |license|
|
||||
context "the #{license.title} license" do
|
||||
let(:source) { URI.parse(license.source) }
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ RSpec.describe Licensee do
|
|||
let(:project_path) { fixture_path('mit') }
|
||||
let(:license_path) { fixture_path('mit/LICENSE.txt') }
|
||||
let(:mit_license) { Licensee::License.find('mit') }
|
||||
let(:hidden_license_count) { 36 }
|
||||
let(:hidden_license_count) { 34 }
|
||||
|
||||
it 'exposes licenses' do
|
||||
expect(described_class.licenses).to be_an(Array)
|
||||
|
|
Loading…
Reference in New Issue