Class: Licensed::Dependency

Inherits:
License
  • Object
show all
Defined in:
lib/licensed/dependency.rb

Constant Summary collapse

/\A(COPYING|NOTICE|LEGAL)(?:\..*)?\z/i

Constants inherited from License

License::YAML_FRONTMATTER_PATTERN

Instance Attribute Summary collapse

Attributes inherited from License

#text

Instance Method Summary collapse

Methods inherited from License

read, #save

Constructor Details

#initialize(path, metadata = {}) ⇒ Dependency

Returns a new instance of Dependency.



9
10
11
12
# File 'lib/licensed/dependency.rb', line 9

def initialize(path,  = {})
  @path = path
  super 
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/licensed/dependency.rb', line 7

def path
  @path
end

Instance Method Details

#detect_license!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/licensed/dependency.rb', line 18

def detect_license!
  if project.license_file
    license = project.license.key if project.license
  else
    # No license file detected, see if there is one in the GitHub repository
    license, content = Licensed.from_github(self["homepage"])

    # No license in the GitHub repository, see if there is one in the README
    if !license && project.readme
      license = project.license.key if project.license
      content = project.readme.content
    end
  end

  self["license"] = license || package_manager_license || "other"
  self.text = ([content] + self.notices).compact.join("\n" + "-" * 80 + "\n")
end

#noticesObject

Extract legal notices from the dependency source



41
42
43
44
45
46
47
48
# File 'lib/licensed/dependency.rb', line 41

def notices
  files = Dir.foreach(path).select do |file|
    File.file?(File.join(path, file)) && file.match(LEGAL_FILES)
  end
  files.unshift project.license_file.filename if project.license_file

  files.uniq.map { |f| File.read(File.join(path, f)) }
end

#package_manager_licenseObject



36
37
38
# File 'lib/licensed/dependency.rb', line 36

def package_manager_license
  project.license.key if project.license
end

#projectObject



14
15
16
# File 'lib/licensed/dependency.rb', line 14

def project
  @project ||= Licensee::FSProject.new(path, detect_packages: true, detect_readme: true)
end