licensee 3.0.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/licensee/license.rb +15 -6
- data/lib/licensee/licenses.rb +11 -11
- data/lib/licensee/version.rb +1 -1
- data/test/functions.rb +1 -1
- data/test/test_licensee.rb +1 -1
- data/test/test_licensee_exact_matcher.rb +1 -1
- data/test/test_licensee_git_matcher.rb +1 -1
- data/test/test_licensee_levenshtein_matcher.rb +1 -1
- data/test/test_licensee_license.rb +20 -0
- data/test/test_licensee_license_file.rb +1 -1
- data/test/test_licensee_licenses.rb +4 -4
- data/test/test_licensee_project.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d766a47dd9215350c16975d59ac9053d2e1b2e7
|
4
|
+
data.tar.gz: df2aed7e4d51620490bc20737beddf11c3f4ffca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea10fa6deca9df416c8977d1577be155ed13a12d8750c593ed9da4d034ac052f4043800a8c06d7fc86bed1c3bb153850fad1abd4cebefede831754f1534feb03
|
7
|
+
data.tar.gz: 5dd629e1f02dba2d815eb052d3ae99be780196fbecd53c512002afdf28703ad4a8ad9cbfeac52fa39fd3b7dd1032b72f8f6fb314c26589b72c5c23349323ca19
|
data/README.md
CHANGED
@@ -34,7 +34,10 @@ Licensee will even diff the distributed license with the original, so you can se
|
|
34
34
|
license = Licensee.license "/path/to/a/project"
|
35
35
|
=> #<Licensee::License name="MIT" match=0.9842154131847726>
|
36
36
|
|
37
|
-
license.
|
37
|
+
license.key
|
38
|
+
=> "mit"
|
39
|
+
|
40
|
+
license.name
|
38
41
|
=> "MIT License"
|
39
42
|
|
40
43
|
license.meta["source"]
|
data/lib/licensee/license.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
class Licensee
|
2
2
|
class License
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :key
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(key)
|
6
|
+
@key=key.downcase
|
7
7
|
end
|
8
8
|
|
9
9
|
# Path to vendored license file on disk
|
10
10
|
def path
|
11
|
-
@path ||= File.expand_path "#{@
|
11
|
+
@path ||= File.expand_path "#{@key}.txt", Licensee::Licenses.base
|
12
12
|
end
|
13
13
|
|
14
14
|
# Raw content of license file, including YAML front matter
|
@@ -18,11 +18,20 @@ class Licensee
|
|
18
18
|
|
19
19
|
# License metadata from YAML front matter
|
20
20
|
def meta
|
21
|
-
@meta ||=
|
21
|
+
@meta ||= YAML.load(parts[1]) if parts[1]
|
22
22
|
rescue
|
23
23
|
nil
|
24
24
|
end
|
25
25
|
|
26
|
+
def name
|
27
|
+
meta["title"] if meta
|
28
|
+
end
|
29
|
+
|
30
|
+
def featured?
|
31
|
+
meta["featured"] if meta
|
32
|
+
end
|
33
|
+
alias_method :featured, :featured?
|
34
|
+
|
26
35
|
# The license body (e.g., contents - frontmatter)
|
27
36
|
def body
|
28
37
|
@body ||= parts[2]
|
@@ -42,7 +51,7 @@ class Licensee
|
|
42
51
|
end
|
43
52
|
|
44
53
|
def inspect
|
45
|
-
"#<Licensee::License name=\"#{name}\">"
|
54
|
+
"#<Licensee::License key= \"#{key}\" name=\"#{name}\">"
|
46
55
|
end
|
47
56
|
|
48
57
|
private
|
data/lib/licensee/licenses.rb
CHANGED
@@ -6,14 +6,14 @@ class Licensee
|
|
6
6
|
def list
|
7
7
|
@licenses ||= begin
|
8
8
|
licenses = []
|
9
|
-
|
9
|
+
keys.each { |key| licenses.push License.new(key) }
|
10
10
|
licenses
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
# Given a license
|
15
|
-
def find(
|
16
|
-
list.find { |l| l.
|
14
|
+
# Given a license key, attempt to return a matching Licensee::License instance
|
15
|
+
def find(key)
|
16
|
+
list.find { |l| l.key.downcase == key.downcase }
|
17
17
|
end
|
18
18
|
|
19
19
|
# Path to vendored licenses
|
@@ -23,13 +23,13 @@ class Licensee
|
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
-
# Returns a list of potential license
|
27
|
-
def
|
28
|
-
@
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
# Returns a list of potential license keys, as vendored
|
27
|
+
def keys
|
28
|
+
@keys ||= begin
|
29
|
+
keyes = Dir.entries(base)
|
30
|
+
keyes.map! { |l| File.basename(l, ".txt").downcase }
|
31
|
+
keyes.reject! { |l| l =~ /^\./ || l.nil? }
|
32
|
+
keyes
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
data/lib/licensee/version.rb
CHANGED
data/test/functions.rb
CHANGED
@@ -57,7 +57,7 @@ def verify_license_file(license, chaos = false, wrap=false)
|
|
57
57
|
|
58
58
|
actual = license_file.match
|
59
59
|
assert actual, "No match for #{expected}."
|
60
|
-
assert_equal expected, actual.
|
60
|
+
assert_equal expected, actual.key, "expeceted #{expected} but got #{actual.key} for .match. Confidence: #{license_file.confidence}. Method: #{license_file.matcher.class}"
|
61
61
|
end
|
62
62
|
|
63
63
|
def wrap(text, line_width=80)
|
data/test/test_licensee.rb
CHANGED
@@ -8,7 +8,7 @@ class TestLicensee < Minitest::Test
|
|
8
8
|
end
|
9
9
|
|
10
10
|
should "detect a project's license" do
|
11
|
-
assert_equal "mit", Licensee.license(fixture_path("licenses.git")).
|
11
|
+
assert_equal "mit", Licensee.license(fixture_path("licenses.git")).key
|
12
12
|
end
|
13
13
|
|
14
14
|
should "diff a license" do
|
@@ -9,7 +9,7 @@ class TestLicenseeExactMatcher < Minitest::Test
|
|
9
9
|
end
|
10
10
|
|
11
11
|
should "match the license" do
|
12
|
-
assert_equal "mit", Licensee::ExactMatcher.match(@mit).
|
12
|
+
assert_equal "mit", Licensee::ExactMatcher.match(@mit).key
|
13
13
|
end
|
14
14
|
|
15
15
|
should "know the match confidence" do
|
@@ -9,7 +9,7 @@ class TestLicenseeLevenshteinMatcher < Minitest::Test
|
|
9
9
|
end
|
10
10
|
|
11
11
|
should "match the license" do
|
12
|
-
assert_equal "mit", Licensee::LevenshteinMatcher.match(@mit).
|
12
|
+
assert_equal "mit", Licensee::LevenshteinMatcher.match(@mit).key
|
13
13
|
end
|
14
14
|
|
15
15
|
should "know the match confidence" do
|
@@ -15,4 +15,24 @@ class TestLicenseeLicense < Minitest::Test
|
|
15
15
|
assert_equal "MIT License", @license.meta["title"]
|
16
16
|
end
|
17
17
|
|
18
|
+
should "know the license path" do
|
19
|
+
assert_equal File.expand_path("./vendor/choosealicense.com/_licenses/mit.txt"), @license.path
|
20
|
+
end
|
21
|
+
|
22
|
+
should "know the license name" do
|
23
|
+
assert_equal "MIT License", @license.name
|
24
|
+
end
|
25
|
+
|
26
|
+
should "know the license ID" do
|
27
|
+
assert_equal "mit", @license.key
|
28
|
+
end
|
29
|
+
|
30
|
+
should "know if the license is featured" do
|
31
|
+
assert @license.featured?
|
32
|
+
refute Licensee::License.new("cc0").featured?
|
33
|
+
end
|
34
|
+
|
35
|
+
should "parse the license parts" do
|
36
|
+
assert_equal 3, @license.send(:parts).size
|
37
|
+
end
|
18
38
|
end
|
@@ -3,8 +3,8 @@ require 'helper'
|
|
3
3
|
class TestLicenseeLicenses < Minitest::Test
|
4
4
|
|
5
5
|
should "know license names" do
|
6
|
-
assert_equal Array, Licensee::Licenses.send(:
|
7
|
-
assert_equal 15, Licensee::Licenses.send(:
|
6
|
+
assert_equal Array, Licensee::Licenses.send(:keys).class
|
7
|
+
assert_equal 15, Licensee::Licenses.send(:keys).size
|
8
8
|
end
|
9
9
|
|
10
10
|
should "load the licenses" do
|
@@ -14,8 +14,8 @@ class TestLicenseeLicenses < Minitest::Test
|
|
14
14
|
end
|
15
15
|
|
16
16
|
should "find a license" do
|
17
|
-
assert_equal "mit", Licensee::Licenses.find("mit").
|
18
|
-
assert_equal "mit", Licensee::Licenses.find("MIT").
|
17
|
+
assert_equal "mit", Licensee::Licenses.find("mit").key
|
18
|
+
assert_equal "mit", Licensee::Licenses.find("MIT").key
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
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:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Balter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rugged
|