lib/licensed/dependency.rb in licensed-0.11.1 vs lib/licensed/dependency.rb in licensed-1.0.0
- old
+ new
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
require "licensee"
module Licensed
class Dependency < License
LEGAL_FILES = /\A(AUTHORS|COPYING|NOTICE|LEGAL)(?:\..*)?\z/i
@@ -9,33 +10,38 @@
def initialize(path, metadata = {})
@path = path
@search_root = metadata.delete("search_root")
- # with licensee now providing license_file[:dir],
+ # with licensee providing license_file[:dir],
# enforcing absolute paths makes life much easier when determining
- # an absolute file path in notices\
+ # an absolute file path in notices
unless Pathname.new(path).absolute?
raise "Dependency path #{path} must be absolute"
end
super metadata
end
+ # Returns a Licensee::Projects::FSProject for the dependency path
def project
@project ||= Licensee::Projects::FSProject.new(path, search_root: search_root, detect_packages: true, detect_readme: true)
end
+ # 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")
end
# Extract legal notices from the dependency source
def notices
local_files.uniq.map { |f| File.read(f) }
end
+ # Returns an array of file paths used to locate legal notices
def local_files
return [] unless Dir.exist?(path)
Dir.foreach(path).map do |file|
next unless file.match(LEGAL_FILES)