class LicenseScout::Dependency

Attributes

license[R]
name[R]
path[R]
type[R]
version[R]

Public Class Methods

new(name, version, path, type) click to toggle source
# File lib/license_scout/dependency.rb, line 31
def initialize(name, version, path, type)
  @name = name
  @version = version
  @path = path
  @type = type

  if path.nil?
    @license = LicenseScout::License.new
  elsif path =~ /^http/ || File.directory?(path)
    @license = LicenseScout::License.new(path)
  else
    raise LicenseScout::Exceptions::MissingSourceDirectory.new("Could not find the source for '#{name}' in the following directories:\n\t * #{path}")
  end

  fallbacks = LicenseScout::Config.fallbacks.send(type.to_sym).select { |f| f["name"] =~ uid_regexp }
  fallbacks.each do |fallback|
    license.add_license(fallback["license_id"], "license_scout fallback", fallback["license_file"], force: true)
  end
end

Public Instance Methods

<=>(other) click to toggle source

Be able to sort dependencies by type, then name, then version

# File lib/license_scout/dependency.rb, line 91
def <=>(other)
  "#{type}#{name}#{version}" <=> "#{other.type}#{other.name}#{other.version}"
end
add_license(license_id, source, contents_url = nil) click to toggle source

Capture a license that was specified in metadata

@param license_id [String] The license as specified in the metadata file @param source [String] Where we found the license info @param contents_url [String] Where we can find the contents of the license

@return [void]

# File lib/license_scout/dependency.rb, line 72
def add_license(license_id, source, contents_url = nil)
  LicenseScout::Log.debug("[#{type}] Adding #{license_id} license for #{name} from #{source}")
  license.add_license(license_id, source, contents_url, {})
end
eql?(other) click to toggle source

@return [Boolean] Whether or not this object is equal to another one. Used for Set uniqueness.

# File lib/license_scout/dependency.rb, line 96
def eql?(other)
  other.is_a?(self.class) && other.hash == hash
end
exception_reason() click to toggle source
# File lib/license_scout/dependency.rb, line 82
def exception_reason
  if has_exception?
    exceptions.first.dig("reason")
  else
    nil
  end
end
exceptions() click to toggle source
# File lib/license_scout/dependency.rb, line 61
def exceptions
  @exceptions ||= LicenseScout::Config.exceptions.send(type.to_sym).select { |e| e["name"] =~ uid_regexp }
end
has_exception?() click to toggle source

Determine if this dependency has an exception. Will match an exception for both the name and the name+version

# File lib/license_scout/dependency.rb, line 78
def has_exception?
  exceptions.any?
end
hash() click to toggle source

@return [Integer] A hashcode that can be used to idenitfy this object. Used for Set uniqueness.

# File lib/license_scout/dependency.rb, line 101
def hash
  [type, name, version].hash
end
uid() click to toggle source

@return [String] The UID for this dependency. Example: bundler (1.16.1)

# File lib/license_scout/dependency.rb, line 52
def uid
  "#{name} (#{version})"
end
uid_regexp() click to toggle source

@return [Regexp] The regular expression that can be used to identify this dependency

# File lib/license_scout/dependency.rb, line 57
def uid_regexp
  Regexp.new("#{Regexp.escape(name)}(\s+\\(#{Regexp.escape(version)}\\))?")
end