Add dist.ini file matcher for Perl modules using Dist::Zilla

This commit is contained in:
Pablo Rodríguez González 2017-01-08 00:39:06 +01:00
parent 1bde890782
commit ebc6d23e0d
5 changed files with 49 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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' }