Class: Licensed::Sources::Gradle::Dependency

Inherits:
Dependency
  • Object
show all
Defined in:
lib/licensed/sources/gradle.rb

Constant Summary

Constants inherited from Dependency

Dependency::LEGAL_FILES_PATTERN

Instance Attribute Summary

Attributes inherited from Dependency

#additional_terms, #errors, #name, #path, #version

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Dependency

#errors?, #license_contents, #license_key, #metadata, #notice_contents, #record

Constructor Details

#initialize(name:, version:, path:, url:, metadata: {}) ⇒ Dependency

Returns a new instance of Dependency.



23
24
25
26
# File 'lib/licensed/sources/gradle.rb', line 23

def initialize(name:, version:, path:, url:, metadata: {})
  @url = url
  super(name: name, version: version, path: path, metadata: )
end

Class Method Details

.retrieve_license(url) ⇒ Object

Cache and return the results of getting the license content.



18
19
20
# File 'lib/licensed/sources/gradle.rb', line 18

def retrieve_license(url)
  (@licenses ||= {})[url] ||= Net::HTTP.get(URI(url))
end

Instance Method Details

#exist?Boolean

Returns whether the dependency content exists

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/licensed/sources/gradle.rb', line 29

def exist?
  # shouldn't force network connections just to check if content exists
  # only check that the path is not empty
  !path.to_s.empty?
end

#project_filesObject

Returns a Licensee::ProjectFiles::LicenseFile for the dependency



36
37
38
39
40
41
# File 'lib/licensed/sources/gradle.rb', line 36

def project_files
  return [] if @url.nil?

  license_data = self.class.retrieve_license(@url)
  Array(Licensee::ProjectFiles::LicenseFile.new(license_data, { uri: @url }))
end