mirror of https://github.com/licensee/licensee.git
Add dist.ini file matcher for Perl modules using Dist::Zilla
This commit is contained in:
parent
1bde890782
commit
ebc6d23e0d
|
@ -22,6 +22,7 @@ require_relative 'licensee/matchers/package_matcher'
|
|||
require_relative 'licensee/matchers/gemspec_matcher'
|
||||
require_relative 'licensee/matchers/npm_bower_matcher'
|
||||
require_relative 'licensee/matchers/cran_matcher'
|
||||
require_relative 'licensee/matchers/dist_zilla_matcher'
|
||||
|
||||
module Licensee
|
||||
# Over which percent is a match considered a match by default
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
module Licensee
|
||||
module Matchers
|
||||
class DistZilla < Package
|
||||
attr_reader :file
|
||||
|
||||
LICENSE_REGEX = /
|
||||
^license\s*=\s*([a-z\-0-9\.]+)
|
||||
/ix
|
||||
|
||||
private
|
||||
|
||||
def license_property
|
||||
match = @file.content.match LICENSE_REGEX
|
||||
match[1].downcase if match && match[1]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,6 +10,8 @@ module Licensee
|
|||
else
|
||||
if filename == 'DESCRIPTION' && content.start_with?('Package:')
|
||||
[Matchers::Cran]
|
||||
elsif filename == 'dist.ini'
|
||||
[Matchers::DistZilla]
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
@ -19,6 +21,7 @@ module Licensee
|
|||
def self.name_score(filename)
|
||||
return 1.0 if ::File.extname(filename) == '.gemspec'
|
||||
return 1.0 if filename == 'package.json'
|
||||
return 0.95 if filename == 'dist.ini'
|
||||
return 0.9 if filename == 'DESCRIPTION'
|
||||
return 0.75 if filename == 'bower.json'
|
||||
0.0
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
RSpec.describe Licensee::Matchers::DistZilla do
|
||||
let(:mit) { Licensee::License.find('mit') }
|
||||
let(:content) { 'license = MIT' }
|
||||
let(:file) { Licensee::Project::LicenseFile.new(content, 'dist.ini') }
|
||||
subject { described_class.new(file) }
|
||||
|
||||
it 'stores the file' do
|
||||
expect(subject.file).to eql(file)
|
||||
end
|
||||
|
||||
it 'has confidence' do
|
||||
expect(subject.confidence).to eql(90)
|
||||
end
|
||||
|
||||
it 'matches' do
|
||||
expect(subject.match).to eql(mit)
|
||||
end
|
||||
end
|
|
@ -7,6 +7,7 @@ RSpec.describe Licensee::Project::PackageInfo do
|
|||
{
|
||||
'licensee.gemspec' => 1.0,
|
||||
'package.json' => 1.0,
|
||||
'dist.ini' => 0.95,
|
||||
'DESCRIPTION' => 0.9,
|
||||
'bower.json' => 0.75,
|
||||
'README.md' => 0.0
|
||||
|
@ -39,6 +40,14 @@ RSpec.describe Licensee::Project::PackageInfo do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with dist.ini' do
|
||||
let(:filename) { 'dist.ini' }
|
||||
|
||||
it 'returns the DistZilla matcher' do
|
||||
expect(possible_matchers).to eql([Licensee::Matchers::DistZilla])
|
||||
end
|
||||
end
|
||||
|
||||
context 'with DESCRIPTION' do
|
||||
let(:filename) { 'DESCRIPTION' }
|
||||
let(:content) { 'Package: test' }
|
||||
|
|
Loading…
Reference in New Issue