lib/licensed/dependency.rb in licensed-1.0.0 vs lib/licensed/dependency.rb in licensed-1.0.1
- old
+ new
@@ -30,16 +30,20 @@
# Detects license information and sets it on this dependency object.
# After calling `detect_license!``, the license is set at
# `dependency["license"]` and legal text is set to `dependency.text`
def detect_license!
self["license"] = license_key
- self.text = ([license_text] + self.notices).compact.join("\n" + "-" * 80 + "\n")
+ self.text = [license_text, *notices].join("\n" + TEXT_SEPARATOR + "\n").strip
end
# Extract legal notices from the dependency source
def notices
- local_files.uniq.map { |f| File.read(f) }
+ local_files.uniq # unique local file paths
+ .sort # sorted by the path
+ .map { |f| File.read(f) } # read the file contents
+ .map(&:strip) # strip whitespace
+ .select { |t| t.length > 0 } # files with content only
end
# Returns an array of file paths used to locate legal notices
def local_files
return [] unless Dir.exist?(path)
@@ -72,10 +76,11 @@
end
# Returns a Licensee::LicenseFile with the content of the license in the
# dependency's repository to account for LICENSE files not being distributed
def remote_license_file
- @remote_license_file ||= Licensed.from_github(self["homepage"])
+ return @remote_license_file if defined?(@remote_license_file)
+ @remote_license_file = Licensed.from_github(self["homepage"])
end
# Regardless of the license detected, try to pull the license content
# from the local LICENSE, remote LICENSE, or the README, in that order
def license_text