diff options
| author | mo khan <mo.khan@gmail.com> | 2020-04-25 17:37:41 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-04-25 17:37:41 -0600 |
| commit | 2637ee99cd2f31ff4fcf04e4cabecbfa0e06ffbb (patch) | |
| tree | dddceade8540ae36ce2ee2ad084f2cfea1b74c91 | |
| parent | a73590a3f54c0c0022328b2b499177ea832cf414 (diff) | |
Fix some specs
| -rw-r--r-- | .github/licensed/bundler/fuzzy_match.dep.yml | 32 | ||||
| -rw-r--r-- | lib/spandx.rb | 1 | ||||
| -rw-r--r-- | lib/spandx/core/cache.rb | 5 | ||||
| -rw-r--r-- | lib/spandx/core/guess.rb | 6 | ||||
| -rw-r--r-- | lib/spandx/dotnet/index.rb | 9 | ||||
| m--------- | spec/fixtures/spdx | 0 | ||||
| -rw-r--r-- | spec/integration/core/cache_spec.rb | 4 |
7 files changed, 45 insertions, 12 deletions
diff --git a/.github/licensed/bundler/fuzzy_match.dep.yml b/.github/licensed/bundler/fuzzy_match.dep.yml new file mode 100644 index 0000000..7351191 --- /dev/null +++ b/.github/licensed/bundler/fuzzy_match.dep.yml @@ -0,0 +1,32 @@ +--- +name: fuzzy_match +version: 2.1.0 +type: bundler +summary: Find a needle in a haystack using string similarity and (optionally) regexp + rules. Replaces loose_tight_dictionary. +homepage: https://github.com/seamusabshere/fuzzy_match +license: mit +licenses: +- sources: LICENSE + text: | + Copyright 2011 Brighter Planet, Inc. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +notices: [] diff --git a/lib/spandx.rb b/lib/spandx.rb index dbd09e6..adafb68 100644 --- a/lib/spandx.rb +++ b/lib/spandx.rb @@ -4,6 +4,7 @@ require 'addressable/uri' require 'bundler' require 'csv' require 'forwardable' +require 'fuzzy_match' require 'json' require 'logger' require 'net/hippie' diff --git a/lib/spandx/core/cache.rb b/lib/spandx/core/cache.rb index ed2d183..5a813ec 100644 --- a/lib/spandx/core/cache.rb +++ b/lib/spandx/core/cache.rb @@ -5,7 +5,7 @@ module Spandx class Cache attr_reader :package_manager, :root - def initialize(package_manager, root: Spandx.git[:cache].path) + def initialize(package_manager, root: "#{Spandx.git[:cache].path}/.index") @package_manager = package_manager @cache = {} @lines = {} @@ -34,7 +34,6 @@ module Spandx def search(name:, version:) datafile = datafile_for(name) - puts ' read: ' + datafile open_file(datafile) do |io| search_for("#{name}-#{version}", io, @lines.fetch(datafile) { |key| @lines[key] = lines_in(io) }) end @@ -44,7 +43,7 @@ module Spandx end def datafile_for(name) - "#{root}/#{key_for(name)}/#{package_manager}" + "#{key_for(name)}/#{package_manager}" end def lines_in(io) diff --git a/lib/spandx/core/guess.rb b/lib/spandx/core/guess.rb index 80a9c64..fa25064 100644 --- a/lib/spandx/core/guess.rb +++ b/lib/spandx/core/guess.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'fuzzy_match' + module Spandx module Core class Guess @@ -26,7 +26,7 @@ module Spandx content = Content.new(raw) catalogue[raw] || - match_name(content, algorithm) || + match_name(content) || match_body(content, algorithm) || unknown(raw) end @@ -40,7 +40,7 @@ module Spandx license_for(response.body, algorithm: algorithm) end - def match_name(content, algorithm) + def match_name(content) return if content.tokens.size < 2 || content.tokens.size > 10 @name_search.find(content.raw) diff --git a/lib/spandx/dotnet/index.rb b/lib/spandx/dotnet/index.rb index 142dad0..9ad3c8b 100644 --- a/lib/spandx/dotnet/index.rb +++ b/lib/spandx/dotnet/index.rb @@ -56,11 +56,12 @@ module Spandx return if version.nil? || version.empty? csv = CSV.generate_line([name, version, license], force_quotes: true) - path = data_file_for(name) + append(data_file_for(name), csv) + end + + def append(path, data) FileUtils.mkdir_p(File.dirname(path)) - puts 'write: ' + path - puts csv.inspect - IO.write(path, csv, mode: 'a') + IO.write(path, data, mode: 'a') end end end diff --git a/spec/fixtures/spdx b/spec/fixtures/spdx -Subproject ce8bcc00dc76921829baa86cd46c8cc13d75ef7 +Subproject ccb324e264bfa52263fd14993e5fe9058c61645 diff --git a/spec/integration/core/cache_spec.rb b/spec/integration/core/cache_spec.rb index 23e8de3..ef4c477 100644 --- a/spec/integration/core/cache_spec.rb +++ b/spec/integration/core/cache_spec.rb @@ -3,11 +3,11 @@ RSpec.describe Spandx::Core::Cache do RSpec.shared_examples 'each data file' do |package_manager, key| describe "#licenses_for (#{package_manager})" do - subject { described_class.new(package_manager, root: Spandx.git[key].root) } + subject { described_class.new(package_manager, root: "#{Spandx.git[key].root}/.index") } (0x00..0xFF).map { |x| x.to_s(16).upcase.rjust(2, '0').downcase }.each do |hex| context hex do - let(:path) { subject.expand_path(".index/#{hex}/#{package_manager}") } + let(:path) { subject.expand_path("#{hex}/#{package_manager}") } it "is able to find all packages in the #{package_manager} index" do CSV.foreach(path) do |row| |
