class Licensed::Sources::Swift
Public Instance Methods
enabled?()
click to toggle source
# File lib/licensed/sources/swift.rb, line 9 def enabled? return unless Licensed::Shell.tool_available?("swift") && swift_package? File.exist?(package_resolved_file_path) end
enumerate_dependencies()
click to toggle source
# File lib/licensed/sources/swift.rb, line 14 def enumerate_dependencies pins.map { |pin| name = pin["package"] version = pin.dig("state", "version") path = dependency_path_for_url(pin["repositoryURL"]) error = "Unable to determine project path from #{url}" unless path Dependency.new( name: name, path: path, version: version, errors: Array(error), metadata: { "type" => Swift.type, "homepage" => homepage_for_url(pin["repositoryURL"]) } ) } end
Private Instance Methods
dependency_path_for_url(url)
click to toggle source
# File lib/licensed/sources/swift.rb, line 48 def dependency_path_for_url(url) last_path_component = URI(url).path.split("/").last.sub(/\.git$/, "") File.join(config.pwd, ".build", "checkouts", last_path_component) rescue URI::InvalidURIError end
homepage_for_url(url)
click to toggle source
# File lib/licensed/sources/swift.rb, line 54 def homepage_for_url(url) return unless %w{http https}.include?(URI(url).scheme) url.sub(/\.git$/, "") rescue URI::InvalidURIError end
package_resolved_file_path()
click to toggle source
# File lib/licensed/sources/swift.rb, line 60 def package_resolved_file_path File.join(config.pwd, "Package.resolved") end
pins()
click to toggle source
# File lib/licensed/sources/swift.rb, line 36 def pins return @pins if defined?(@pins) @pins = begin json = JSON.parse(File.read(package_resolved_file_path)) json.dig("object", "pins") rescue => e message = "Licensed was unable to read the Package.resolved file. Error: #{e.message}" raise Licensed::Sources::Source::Error, message end end
swift_package?()
click to toggle source
# File lib/licensed/sources/swift.rb, line 64 def swift_package? Licensed::Shell.success?("swift", "package", "describe") end