Class: Licensed::Dependency
- Defined in:
- lib/licensed/dependency.rb
Constant Summary collapse
- LEGAL_FILES =
/\A(AUTHORS|COPYING|NOTICE|LEGAL)(?:\..*)?\z/i
Constants inherited from License
License::YAML_FRONTMATTER_PATTERN
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#search_root ⇒ Object
readonly
Returns the value of attribute search_root.
Attributes inherited from License
Instance Method Summary collapse
- #detect_license! ⇒ Object
-
#initialize(path, metadata = {}) ⇒ Dependency
constructor
A new instance of Dependency.
- #local_files ⇒ Object
-
#notices ⇒ Object
Extract legal notices from the dependency source.
- #project ⇒ Object
Methods inherited from License
Constructor Details
#initialize(path, metadata = {}) ⇒ Dependency
Returns a new instance of Dependency.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/licensed/dependency.rb', line 10 def initialize(path, = {}) @path = path @search_root = .delete("search_root") # with licensee now providing license_file[:dir], # enforcing absolute paths makes life much easier when determining # an absolute file path in notices\ unless Pathname.new(path).absolute? raise "Dependency path #{path} must be absolute" end super end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/licensed/dependency.rb', line 7 def path @path end |
#search_root ⇒ Object (readonly)
Returns the value of attribute search_root.
8 9 10 |
# File 'lib/licensed/dependency.rb', line 8 def search_root @search_root end |
Instance Method Details
#detect_license! ⇒ Object
28 29 30 31 |
# File 'lib/licensed/dependency.rb', line 28 def detect_license! self["license"] = license_key self.text = ([license_text] + self.notices).compact.join("\n" + "-" * 80 + "\n") end |
#local_files ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/licensed/dependency.rb', line 38 def local_files return [] unless Dir.exist?(path) Dir.foreach(path).map do |file| next unless file.match(LEGAL_FILES) file_path = File.join(path, file) next unless File.file?(file_path) file_path end.compact end |
#notices ⇒ Object
Extract legal notices from the dependency source
34 35 36 |
# File 'lib/licensed/dependency.rb', line 34 def notices local_files.uniq.map { |f| File.read(f) } end |
#project ⇒ Object
24 25 26 |
# File 'lib/licensed/dependency.rb', line 24 def project @project ||= Licensee::Projects::FSProject.new(path, search_root: search_root, detect_packages: true, detect_readme: true) end |