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 /lib | |
| parent | a73590a3f54c0c0022328b2b499177ea832cf414 (diff) | |
Fix some specs
Diffstat (limited to 'lib')
| -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 |
4 files changed, 11 insertions, 10 deletions
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 |
