Class: Spandx::Js::YarnPkg

Inherits:
Core::Gateway show all
Defined in:
lib/spandx/js/yarn_pkg.rb

Constant Summary collapse

DEFAULT_SOURCE =
'https://registry.yarnpkg.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Core::Registerable

#all, #each, #inherited, #registry

Constructor Details

#initialize(http: Spandx.http) ⇒ YarnPkg

Returns a new instance of YarnPkg.



9
10
11
# File 'lib/spandx/js/yarn_pkg.rb', line 9

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

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



7
8
9
# File 'lib/spandx/js/yarn_pkg.rb', line 7

def http
  @http
end

Instance Method Details

#licenses_for(dependency) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/spandx/js/yarn_pkg.rb', line 17

def licenses_for(dependency)
   = (dependency)

  return [] if .empty?

  [['license']].compact
end

#matches?(dependency) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/spandx/js/yarn_pkg.rb', line 13

def matches?(dependency)
  %i[npm yarn].include?(dependency.package_manager)
end

#metadata_for(dependency) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/spandx/js/yarn_pkg.rb', line 25

def (dependency)
  uri = uri_for(dependency)
  response = http.get(uri, escape: false)

  if http.ok?(response)
    json = Oj.load(response.body)
    json['versions'] ? json['versions'][dependency.version] : json
  else
    {}
  end
end