hide hidden licenses by default

This commit is contained in:
Ben Balter 2015-09-01 10:36:27 -04:00
parent 20c24e2f1a
commit fa3dcf3c4d
8 changed files with 21 additions and 10 deletions

View File

@ -30,8 +30,8 @@ class Licensee
attr_writer :confidence_threshold, :package_manager_files
# Returns an array of Licensee::License instances
def licenses
@licenses ||= Licensee::License.all
def licenses(options={})
Licensee::License.all(options)
end
# Returns the license for a given git repo

View File

@ -12,7 +12,8 @@ class Licensee
@keys ||= license_files.map { |l| File.basename(l, ".txt").downcase }
end
def find(key,options={})
def find(key, options={})
options = {:hidden => true}.merge(options)
key = key.downcase
all(options).find { |license| license.key == key }
end
@ -113,6 +114,10 @@ class Licensee
URI.join(Licensee::DOMAIN, "/licenses/#{key}/").to_s
end
def ==(other)
key == other.key
end
private
def parts

View File

@ -1,7 +1,7 @@
class Licensee
class ExactMatcher < Matcher
def match
Licensee.licenses.find { |l| l.body_normalized == file.content_normalized }
Licensee.licenses(:hidden => true).find { |l| l.body_normalized == file.content_normalized }
end
def confidence

View File

@ -12,7 +12,7 @@ class Licensee
private
def matches
@matches ||= Licensee.licenses.map { |l| [l, file.similarity(l)] }.select { |l,sim| sim > 0 }
@matches ||= Licensee.licenses(:hidden => true).map { |l| [l, file.similarity(l)] }.select { |l,sim| sim > 0 }
end
# Pulled out for easier testing

View File

@ -12,7 +12,7 @@ class Licensee
# Difference in lengths cannot exceed the file's length * the confidence threshold / 100
def potential_licenses
@potential_licenses ||= begin
Licensee.licenses.select { |license| length_delta(license) <= max_delta }.sort_by { |l| length_delta(l) }
Licensee.licenses(:hidden => true).select { |license| length_delta(license) <= max_delta }.sort_by { |l| length_delta(l) }
end
end

View File

@ -2,7 +2,7 @@ class Licensee
class PackageMatcher < Matcher
def match
Licensee.licenses.find { |l| l.key == license_property } if file.package?
Licensee.licenses(:hidden => true).find { |l| l.key == license_property } if file.package?
end
def confidence

View File

@ -3,7 +3,8 @@ require 'helper'
class TestLicensee < Minitest::Test
should "know the licenses" do
assert_equal Array, Licensee.licenses.class
assert_equal 19, Licensee.licenses.size
assert_equal 15, Licensee.licenses.size
assert_equal 19, Licensee.licenses(:hidden => true).size
assert_equal Licensee::License, Licensee.licenses.first.class
end

View File

@ -34,6 +34,11 @@ class TestLicenseeLicense < Minitest::Test
assert_equal "mit", @license.key
end
should "know license equality" do
assert @license == Licensee::License.new("MIT")
refute @license == Licensee::License.new("ISC")
end
should "know if the license is featured" do
assert @license.featured?
assert_equal TrueClass, @license.featured?.class
@ -58,7 +63,6 @@ class TestLicenseeLicense < Minitest::Test
refute @license.hidden?
assert Licensee::License.new("ofl-1.1").hidden?
assert Licensee::License.new("no-license").hidden?
end
should "parse the license parts" do
@ -97,7 +101,8 @@ class TestLicenseeLicense < Minitest::Test
should "load the licenses" do
assert_equal Array, Licensee::License.all.class
assert_equal 19, Licensee::License.all.size
assert_equal 15, Licensee::License.all.size
assert_equal 19, Licensee::License.all(:hidden => true).size
assert_equal Licensee::License, Licensee::License.all.first.class
end