Class: Spandx::Php::PackagistGateway

Inherits:
Core::Gateway show all
Defined in:
lib/spandx/php/packagist_gateway.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Core::Registerable

#all, #each, #inherited, #registry

Constructor Details

#initialize(http: Spandx.http) ⇒ PackagistGateway

Returns a new instance of PackagistGateway.



8
9
10
# File 'lib/spandx/php/packagist_gateway.rb', line 8

def initialize(http: Spandx.http)
  @http = http
end

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



6
7
8
# File 'lib/spandx/php/packagist_gateway.rb', line 6

def http
  @http
end

Instance Method Details

#licenses_for(dependency) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/spandx/php/packagist_gateway.rb', line 16

def licenses_for(dependency)
  response = http.get("https://repo.packagist.org/p/#{dependency.name}.json")
  return [] unless http.ok?(response)

  json = Oj.load(response.body)
  json['packages'][dependency.name][dependency.version]['license']
end

#matches?(dependency) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/spandx/php/packagist_gateway.rb', line 12

def matches?(dependency)
  dependency.package_manager == :composer
end