diff --git a/lib/licensee.rb b/lib/licensee.rb index a9111e0..32e4734 100644 --- a/lib/licensee.rb +++ b/lib/licensee.rb @@ -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 diff --git a/lib/licensee/matchers/dist_zilla_matcher.rb b/lib/licensee/matchers/dist_zilla_matcher.rb new file mode 100644 index 0000000..c4b475b --- /dev/null +++ b/lib/licensee/matchers/dist_zilla_matcher.rb @@ -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 diff --git a/lib/licensee/project_files/package_info.rb b/lib/licensee/project_files/package_info.rb index f14668c..fe03f8e 100644 --- a/lib/licensee/project_files/package_info.rb +++ b/lib/licensee/project_files/package_info.rb @@ -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 diff --git a/spec/licensee/matchers/dist_zilla_matcher_spec.rb b/spec/licensee/matchers/dist_zilla_matcher_spec.rb new file mode 100644 index 0000000..6a58068 --- /dev/null +++ b/spec/licensee/matchers/dist_zilla_matcher_spec.rb @@ -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 diff --git a/spec/licensee/project_files/package_info_spec.rb b/spec/licensee/project_files/package_info_spec.rb index 1e3da91..85cb56a 100644 --- a/spec/licensee/project_files/package_info_spec.rb +++ b/spec/licensee/project_files/package_info_spec.rb @@ -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' }