licensee 5.0.0b1 → 5.0.0b2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49baf7865bddf84e8237149cba6f21768e661c39
4
- data.tar.gz: 95dbc39d96bed4d0952df9e85eb56ae37f387c1f
3
+ metadata.gz: 9275866e83088fd301ad334a09190133d210c398
4
+ data.tar.gz: d679bb4b0813cbd065b49abd05fe5256f2a551af
5
5
  SHA512:
6
- metadata.gz: 60a4c027e6d388d732ad3588606c380d90595be0955f55e9415a727370c78c8faff40c781843bc04989fb3a591821f91579079f54c2197f02778e9cac6cb73a3
7
- data.tar.gz: 510467b863f02cdb658986dd5626460d0383c5602d22c3f170094d7d38bf80e56727691a4c8fc30dc7b4c79003a610383a90dfa4864fc87b1f3a4f83eb404012
6
+ metadata.gz: 5ff54bc4e9472afd1230c41119ce5c450a1a63e43b49c7312e610bee3b0aaadb2b3aa2e426339d8238f7b02a4d14f43dc392d414c7432d4a665dbc260332aee4
7
+ data.tar.gz: ca076a720d1e9962df28e24641ce7f7337fee22ac838da9f5b66cda1fa440d1e8224b9e3804530e5a0dafd8ed399dc69143c251bf664c7751408b005c9a4d591
@@ -30,8 +30,8 @@ class Licensee
30
30
  attr_writer :confidence_threshold, :package_manager_files
31
31
 
32
32
  # Returns an array of Licensee::License instances
33
- def licenses
34
- @licenses ||= Licensee::License.all
33
+ def licenses(options={})
34
+ Licensee::License.all(options)
35
35
  end
36
36
 
37
37
  # Returns the license for a given git repo
@@ -3,19 +3,22 @@ class Licensee
3
3
  class License
4
4
 
5
5
  class << self
6
- def all
6
+ def all(options={})
7
7
  @all ||= keys.map { |key| self.new(key) }
8
+ options[:hidden] ? @all : @all.reject { |l| l.hidden? }
8
9
  end
9
10
 
10
11
  def keys
11
12
  @keys ||= license_files.map { |l| File.basename(l, ".txt").downcase }
12
13
  end
13
14
 
14
- def find(key)
15
+ def find(key, options={})
16
+ options = {:hidden => true}.merge(options)
15
17
  key = key.downcase
16
- all.find { |l| l.key == key }
18
+ all(options).find { |license| license.key == key }
17
19
  end
18
20
  alias_method :[], :find
21
+ alias_method :find_by_key, :find
19
22
 
20
23
  def license_dir
21
24
  File.expand_path "../../vendor/choosealicense.com/_licenses", File.dirname(__FILE__)
@@ -111,6 +114,10 @@ class Licensee
111
114
  URI.join(Licensee::DOMAIN, "/licenses/#{key}/").to_s
112
115
  end
113
116
 
117
+ def ==(other)
118
+ key == other.key
119
+ end
120
+
114
121
  private
115
122
 
116
123
  def parts
@@ -1,7 +1,7 @@
1
1
  class Licensee
2
2
  class ExactMatcher < Matcher
3
3
  def match
4
- Licensee.licenses.find { |l| l.body_normalized == file.content_normalized }
4
+ Licensee.licenses(:hidden => true).find { |l| l.body_normalized == file.content_normalized }
5
5
  end
6
6
 
7
7
  def confidence
@@ -12,7 +12,7 @@ class Licensee
12
12
  private
13
13
 
14
14
  def matches
15
- @matches ||= Licensee.licenses.map { |l| [l, file.similarity(l)] }.select { |l,sim| sim > 0 }
15
+ @matches ||= Licensee.licenses(:hidden => true).map { |l| [l, file.similarity(l)] }.select { |l,sim| sim > 0 }
16
16
  end
17
17
 
18
18
  # Pulled out for easier testing
@@ -12,7 +12,7 @@ class Licensee
12
12
  # Difference in lengths cannot exceed the file's length * the confidence threshold / 100
13
13
  def potential_licenses
14
14
  @potential_licenses ||= begin
15
- Licensee.licenses.select { |license| length_delta(license) <= max_delta }.sort_by { |l| length_delta(l) }
15
+ Licensee.licenses(:hidden => true).select { |license| length_delta(license) <= max_delta }.sort_by { |l| length_delta(l) }
16
16
  end
17
17
  end
18
18
 
@@ -2,7 +2,7 @@ class Licensee
2
2
  class PackageMatcher < Matcher
3
3
 
4
4
  def match
5
- Licensee.licenses.find { |l| l.key == license_property } if file.package?
5
+ Licensee.licenses(:hidden => true).find { |l| l.key == license_property } if file.package?
6
6
  end
7
7
 
8
8
  def confidence
@@ -36,7 +36,8 @@ class Licensee
36
36
  end
37
37
 
38
38
  def matched_file
39
- license_file || package_file
39
+ return license_file if license_file && license_file.match
40
+ return package_file if package_file && package_file.match
40
41
  end
41
42
 
42
43
  private
@@ -1,3 +1,3 @@
1
1
  class Licensee
2
- VERSION = "5.0.0b1"
2
+ VERSION = "5.0.0b2"
3
3
  end
@@ -3,7 +3,8 @@ require 'helper'
3
3
  class TestLicensee < Minitest::Test
4
4
  should "know the licenses" do
5
5
  assert_equal Array, Licensee.licenses.class
6
- assert_equal 19, Licensee.licenses.size
6
+ assert_equal 15, Licensee.licenses.size
7
+ assert_equal 19, Licensee.licenses(:hidden => true).size
7
8
  assert_equal Licensee::License, Licensee.licenses.first.class
8
9
  end
9
10
 
@@ -34,6 +34,11 @@ class TestLicenseeLicense < Minitest::Test
34
34
  assert_equal "mit", @license.key
35
35
  end
36
36
 
37
+ should "know license equality" do
38
+ assert @license == Licensee::License.new("MIT")
39
+ refute @license == Licensee::License.new("ISC")
40
+ end
41
+
37
42
  should "know if the license is featured" do
38
43
  assert @license.featured?
39
44
  assert_equal TrueClass, @license.featured?.class
@@ -58,7 +63,6 @@ class TestLicenseeLicense < Minitest::Test
58
63
  refute @license.hidden?
59
64
  assert Licensee::License.new("ofl-1.1").hidden?
60
65
  assert Licensee::License.new("no-license").hidden?
61
-
62
66
  end
63
67
 
64
68
  should "parse the license parts" do
@@ -97,7 +101,8 @@ class TestLicenseeLicense < Minitest::Test
97
101
 
98
102
  should "load the licenses" do
99
103
  assert_equal Array, Licensee::License.all.class
100
- assert_equal 19, Licensee::License.all.size
104
+ assert_equal 15, Licensee::License.all.size
105
+ assert_equal 19, Licensee::License.all(:hidden => true).size
101
106
  assert_equal Licensee::License, Licensee::License.all.first.class
102
107
  end
103
108
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: licensee
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0b1
4
+ version: 5.0.0b2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-27 00:00:00.000000000 Z
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged