licensee 4.7.0 → 4.7.1

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: de46f921456858704f9f2260d3d699d9ddc61501
4
- data.tar.gz: 043ec663c844f2c845a33aab4df9bd9e70d277a3
3
+ metadata.gz: c12d9b4200c5da5e7b8d9de112cfac32f52d3def
4
+ data.tar.gz: 81a13ed9b414494093be1ebe79a52aa3008a7d99
5
5
  SHA512:
6
- metadata.gz: 497beceba2f3b24cf06bafcf3042e9a202d3aaa8668431c09736cd3bc11267a937d90a522f5ade5ff67e45cdb585d07d1bcc5584034ff84284fc62146d681f94
7
- data.tar.gz: 9e41896143cb6c2bc55f9ac5d6953f506f2d2b8223499bdbdf2f904f4feea9dbf7684a9cbe2a81deb85dc7264a8e006eea02c3cb91d4b6e2a38ff262ea4c8c98
6
+ metadata.gz: 9913ceaf83583b2fa47ffd0389af8e2aaa8219a3efd9243fa01d03a692c35cb4529b482f71ed347e034c549ee8e700aba93c0105c6e13dfa873ee6750cad003b
7
+ data.tar.gz: 3814c71d59f4df84abff4204213130732342b578e06212e0ee9dec632c83ac46f8e0542a1f6deb14513639f7556ddcf04191b676cfcb46471d53404fa8d99504
@@ -30,7 +30,13 @@ class Licensee
30
30
 
31
31
  # License metadata from YAML front matter
32
32
  def meta
33
- @meta ||= YAML.load(parts[1]) if parts && parts[1]
33
+ @meta ||= if parts && parts[1]
34
+ if YAML.respond_to? :safe_yaml
35
+ YAML.safe_load(parts[1])
36
+ else
37
+ YAML.load(parts[1])
38
+ end
39
+ end
34
40
  end
35
41
 
36
42
  # Returns the human-readable license name
@@ -38,13 +38,15 @@ class Licensee
38
38
  #
39
39
  # filename - (string) the name of the file to score
40
40
  #
41
- # Returns 1 if the file is definately a license file
42
- # Return 0.5 if the file is likely a license file
43
- # Returns 0 if the file is definately not a license file
41
+ # Returns 1.0 if the file is definately a license file
42
+ # Returns 0.75 if the file is probably a license file
43
+ # Returns 0.5 if the file is likely a license file
44
+ # Returns 0.0 if the file is definately not a license file
44
45
  def self.match_license_file(filename)
45
- return 1 if self.license_file?(filename)
46
- return 0.5 if self.maybe_license_file?(filename)
47
- return 0
46
+ return 1.0 if filename =~ /\A(un)?licen[sc]e(\.[^.]+)?\z/i
47
+ return 0.75 if filename =~ /\Acopy(ing|right)(\.[^.]+)?\z/i
48
+ return 0.5 if filename =~ /licen[sc]e/i
49
+ return 0.0
48
50
  end
49
51
 
50
52
  private
@@ -60,8 +62,7 @@ class Licensee
60
62
  # Detects the license file, if any
61
63
  # Returns the blob hash as detected in the tree
62
64
  def license_hash
63
- license_hash = tree.find { |blob| self.class.license_file?(blob[:name]) }
64
- license_hash ||= tree.find { |blob| self.class.maybe_license_file?(blob[:name]) }
65
+ tree.sort_by { |blob| self.class.match_license_file(blob[:name]) }.last
65
66
  end
66
67
 
67
68
  def license_blob
@@ -71,26 +72,5 @@ class Licensee
71
72
  def license_path
72
73
  license_hash[:name] if license_hash
73
74
  end
74
-
75
- # Regex to detect license files
76
- #
77
- # Examples it should match:
78
- # - LICENSE.md
79
- # - licence.txt
80
- # - unlicense
81
- # - copying
82
- # - copyright
83
- def self.license_file?(filename)
84
- !!(filename =~ /\A(un)?licen[sc]e|copy(ing|right)(\.[^.]+)?\z/i)
85
- end
86
-
87
- # Regex to detect things that look like license files
88
- #
89
- # Examples it should match:
90
- # - license-MIT.txt
91
- # - MIT-LICENSE
92
- def self.maybe_license_file?(filename)
93
- !!(filename =~ /licen[sc]e/i)
94
- end
95
75
  end
96
76
  end
@@ -1,3 +1,3 @@
1
1
  class Licensee
2
- VERSION = "4.7.0"
2
+ VERSION = "4.7.1"
3
3
  end
@@ -0,0 +1,3 @@
1
+ x��K
2
+ �0 ��)t�d;�RJnbKrȏ�,z��=Bwom�2U�o�/\Уob���L�Q�-:��B6:z��C�
3
+ Y[ʉ;�
@@ -0,0 +1 @@
1
+ 51a11d50f29a14774ded8f7b90ba9938dce78a92
@@ -79,42 +79,29 @@ class TestLicenseeProject < Minitest::Test
79
79
  end
80
80
  end
81
81
 
82
- context "license filename matching" do
83
- # Standard license names
84
- ["license",
85
- "LICENSE",
86
- "LICENCE",
87
- "license.md",
88
- "unlicense",
89
- "unlicence",
90
- "copying",
91
- "copyRIGHT",
92
- "license.txt"
93
- ].each do |license|
94
- should "match #{license}" do
95
- assert Licensee::Project.license_file?(license)
82
+ context "license filename scoring" do
83
+
84
+ EXPECTATIONS = {
85
+ "license" => 1.0,
86
+ "LICENCE" => 1.0,
87
+ "license.md" => 1.0,
88
+ "LICENSE.md" => 1.0,
89
+ "license.txt" => 1.0,
90
+ "unLICENSE" => 1.0,
91
+ "unlicence" => 1.0,
92
+ "COPYING" => 0.75,
93
+ "copyRIGHT" => 0.75,
94
+ "COPYRIGHT.txt" => 0.75,
95
+ "LICENSE-MIT" => 0.5,
96
+ "MIT-LICENSE.txt" => 0.5,
97
+ "mit-license-foo.md" => 0.5,
98
+ "README.txt" => 0.0
99
+ }
100
+
101
+ EXPECTATIONS.each do |filename, expected|
102
+ should "score a license named `#{filename}` as `#{expected}`" do
103
+ assert_equal expected, Licensee::Project.match_license_file(filename)
96
104
  end
97
105
  end
98
-
99
- should "not match MIT-LICENSE" do
100
- refute Licensee::Project.license_file?("MIT-LICENSE")
101
- end
102
-
103
- # Abnormal license names
104
- [
105
- "LICENSE-MIT",
106
- "MIT-LICENSE.txt",
107
- "mit-license-foo.md"
108
- ].each do |license|
109
- should "match #{license}" do
110
- assert Licensee::Project.maybe_license_file?(license)
111
- end
112
- end
113
-
114
- should "return the proper license files scores" do
115
- assert_equal 1, Licensee::Project.match_license_file("LICENSE.md")
116
- assert_equal 0.5, Licensee::Project.match_license_file("MIT-LICENSE")
117
- assert_equal 0, Licensee::Project.match_license_file("README.txt")
118
- end
119
106
  end
120
107
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: licensee
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.7.0
4
+ version: 4.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
@@ -140,10 +140,14 @@ files:
140
140
  - test/fixtures/license-folder.git/refs/heads/master
141
141
  - test/fixtures/licenses.git/HEAD
142
142
  - test/fixtures/licenses.git/config
143
+ - test/fixtures/licenses.git/objects/51/a11d50f29a14774ded8f7b90ba9938dce78a92
144
+ - test/fixtures/licenses.git/objects/5e/df454e6517673d5e64a33cf284308b9c6b1075
145
+ - test/fixtures/licenses.git/objects/e1/b4dc13f4bf683ce8f2943e051c3e91e778d043
143
146
  - test/fixtures/licenses.git/objects/info/packs
144
147
  - test/fixtures/licenses.git/objects/pack/pack-4a7088171ae3ca900f010a4be6f1c2c96490c338.idx
145
148
  - test/fixtures/licenses.git/objects/pack/pack-4a7088171ae3ca900f010a4be6f1c2c96490c338.pack
146
149
  - test/fixtures/licenses.git/packed-refs
150
+ - test/fixtures/licenses.git/refs/heads/master
147
151
  - test/fixtures/named-license-file-prefix.git/HEAD
148
152
  - test/fixtures/named-license-file-prefix.git/config
149
153
  - test/fixtures/named-license-file-prefix.git/objects/64/3983d3f82ecc2a7d8e4227946220ebffd477d2