licensee 4.3.1 → 4.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0532a309a8c4d19ca16a7504da94953bddb0948d
4
- data.tar.gz: 72d573ef81545cb890cf479db81c3424774277ed
3
+ metadata.gz: a01e0662cd476d9f2a5e8764fb2c0147166da2cb
4
+ data.tar.gz: bdf3c4a1438ae6001693c58ed8be7ed04b6ecd53
5
5
  SHA512:
6
- metadata.gz: c7621458e6955c279bd6b458bb25b8b6c947a165a91869e8beae400a0b1ddca92f18b57be6628df07df343fe5908a3d5c16445f7124995e5c3592a5f58a2a483
7
- data.tar.gz: b31f1841f66454f2229ec02245bd5437f188a3c0b5ed18646fcfb68b2c30e7f57f267190422e84a1545000de725d6e7fa2f499747bcadcbc03ab864d8cb245a0
6
+ metadata.gz: 71a8f8837bd03de8ce8f5da7a05d2b781d2c0a51a0df2bbd2b598a372e7fed77309097a81f7ba1a291315161f4b8ed360c9be924e9d86eed48648b7762e64389
7
+ data.tar.gz: 0aa65b6e811f06047422f1676f79f458674b78e74065de526ed82c8d77e99f29afccf9588813494757cf885fd489c166b5224cce60ab23be0dd80c1a600bbcde
data/bin/licensee CHANGED
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative "../lib/licensee"
4
- license = Licensee::Project.new(Dir.pwd).license_file
4
+ project = Licensee::Project.new(Dir.pwd)
5
+ license = project.license_file
5
6
 
6
7
  if license
8
+ puts "License file: #{project.send(:license_blob)[:name]}"
7
9
  puts "License: #{license.match ? license.match.meta['title'] : 'no license'}"
8
10
  puts "Confidence: #{license.confidence}%"
9
11
  puts "Method: #{license.matcher.class}"
@@ -26,26 +26,34 @@ class Licensee
26
26
  @revision = revision
27
27
  end
28
28
 
29
- # Detects the license file, if any
30
- # Returns a Licensee::LicenseFile instance
29
+ # Returns an instance of Licensee::LicenseFile if there's a license file detected
31
30
  def license_file
32
- return @license_file if defined? @license_file
31
+ @license_file ||= LicenseFile.new(@repository.lookup(license_blob[:oid])) if license_blob
32
+ end
33
33
 
34
- commit = @revision ? @repository.lookup(@revision) : @repository.last_commit
35
- tree = commit.tree.select { |blob| blob[:type] == :blob }
34
+ # Returns the matching Licensee::License instance if a license can be detected
35
+ def license
36
+ @license ||= license_file.match if license_file
37
+ end
36
38
 
37
- # Prefer an exact match to one of our known file names
38
- license_blob = tree.find { |blob| LICENSE_FILENAMES.include? blob[:name].downcase }
39
+ private
39
40
 
40
- # Fall back to the first file in the project root that has the word license in it
41
- license_blob = tree.find { |blob| blob[:name] =~ /license/i } unless license_blob
41
+ def commit
42
+ @revision ? @repository.lookup(@revision) : @repository.last_commit
43
+ end
42
44
 
43
- @license_file = LicenseFile.new(@repository.lookup(license_blob[:oid])) if license_blob
45
+ def tree
46
+ commit.tree.select { |blob| blob[:type] == :blob }
44
47
  end
45
48
 
46
- # Returns the matching Licensee::License instance if a license can be detected
47
- def license
48
- @license ||= license_file.match if license_file
49
+ # Detects the license file, if any
50
+ # Returns the blob hash as detected in the tree
51
+ def license_blob
52
+ # Prefer an exact match to one of our known file names
53
+ license_blob = tree.find { |blob| LICENSE_FILENAMES.include? blob[:name].downcase }
54
+
55
+ # Fall back to the first file in the project root that has the word license in it
56
+ license_blob || tree.find { |blob| blob[:name] =~ /licen(s|c)e/i }
49
57
  end
50
58
  end
51
59
  end
@@ -1,3 +1,3 @@
1
1
  class Licensee
2
- VERSION = "4.3.1"
2
+ VERSION = "4.3.2"
3
3
  end
@@ -0,0 +1 @@
1
+ ref: refs/heads/master
@@ -0,0 +1,6 @@
1
+ [core]
2
+ repositoryformatversion = 0
3
+ filemode = true
4
+ bare = true
5
+ ignorecase = true
6
+ precomposeunicode = true
@@ -0,0 +1 @@
1
+ 660c086dc25f9f3b96e7afd9dee8a11b4e614543
@@ -14,6 +14,22 @@ class TestLicenseeProject < Minitest::Test
14
14
  assert_equal "mit", @project.license.key
15
15
  end
16
16
 
17
+ should "know the last commit" do
18
+ commit = @project.send(:commit)
19
+ assert_equal Rugged::Commit, commit.class
20
+ assert_equal "b02cbad9d254c41d16d56ed9d6d2cf07c1d837fd", commit.oid
21
+ end
22
+
23
+ should "retrieve the tree" do
24
+ tree = @project.send(:tree)
25
+ assert_equal 1, tree.count
26
+ assert_equal "bcb552d06d9cf1cd4c048a6d3bf716849c2216cc", tree.first[:oid]
27
+ end
28
+
29
+ should "return the license blob" do
30
+ assert_equal "LICENSE", @project.send(:license_blob)[:name]
31
+ end
32
+
17
33
  should "detect an atypically cased license file" do
18
34
  project = Licensee::Project.new fixture_path("case-sensitive.git")
19
35
  assert_equal Licensee::LicenseFile, project.license_file.class
@@ -33,4 +49,9 @@ class TestLicenseeProject < Minitest::Test
33
49
  project = Licensee::Project.new fixture_path("license-folder.git")
34
50
  assert_equal nil, project.license
35
51
  end
52
+
53
+ should "detect licence files" do
54
+ project = Licensee::Project.new fixture_path("licence.git")
55
+ assert_equal "mit", project.license.key
56
+ end
36
57
  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.3.1
4
+ version: 4.3.2
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-02-27 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
@@ -122,6 +122,13 @@ files:
122
122
  - test/fixtures/case-sensitive.git/objects/2c/b878e0851c5cf53d7455d9018baa6755a38bd7
123
123
  - test/fixtures/case-sensitive.git/objects/fb/ddf40ba5f30225af7cd9841afe374ca5800cb9
124
124
  - test/fixtures/case-sensitive.git/refs/heads/master
125
+ - test/fixtures/licence.git/HEAD
126
+ - test/fixtures/licence.git/config
127
+ - test/fixtures/licence.git/objects/66/0c086dc25f9f3b96e7afd9dee8a11b4e614543
128
+ - test/fixtures/licence.git/objects/68/804815597f79aa323de3257a8fd7b76449943c
129
+ - test/fixtures/licence.git/objects/dd/59aed84c5aa4dff7ceda11a1c045f831194067
130
+ - test/fixtures/licence.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
131
+ - test/fixtures/licence.git/refs/heads/master
125
132
  - test/fixtures/license-folder.git/HEAD
126
133
  - test/fixtures/license-folder.git/config
127
134
  - test/fixtures/license-folder.git/objects/32/6d0761f0c54d54327ea9e127e02d9bae14d2c8