Class: Package::Audit::Npm::NodeCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/package/audit/npm/node_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir, report) ⇒ NodeCollection

Returns a new instance of NodeCollection.



11
12
13
14
# File 'lib/package/audit/npm/node_collection.rb', line 11

def initialize(dir, report)
  @dir = dir
  @report = report
end

Instance Method Details

#allObject



29
30
31
32
33
34
# File 'lib/package/audit/npm/node_collection.rb', line 29

def all
  implicit_pkgs = fetch_from_lock_file
  vulnerable_pkgs = VulnerabilityFinder.new(@dir, implicit_pkgs).run
  pkgs = NpmMetaData.new(vulnerable_pkgs + implicit_pkgs).fetch.filter(&:risk?)
  DuplicatePackageMerger.new(pkgs).run
end

#deprecatedObject



36
37
38
39
40
# File 'lib/package/audit/npm/node_collection.rb', line 36

def deprecated
  implicit_pkgs = fetch_from_lock_file
  pkgs = NpmMetaData.new(implicit_pkgs).fetch.filter(&:deprecated?)
  DuplicatePackageMerger.new(pkgs).run
end

#fetchObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/package/audit/npm/node_collection.rb', line 16

def fetch
  case @report
  when Enum::Report::DEPRECATED
    deprecated
  when Enum::Report::OUTDATED
    outdated
  when Enum::Report::VULNERABLE
    vulnerable
  else
    all
  end
end

#outdatedObject



42
43
44
45
46
# File 'lib/package/audit/npm/node_collection.rb', line 42

def outdated
  implicit_pkgs = fetch_from_lock_file
  pkgs = NpmMetaData.new(implicit_pkgs).fetch.filter(&:outdated?)
  DuplicatePackageMerger.new(pkgs).run
end

#vulnerableObject



48
49
50
51
52
53
# File 'lib/package/audit/npm/node_collection.rb', line 48

def vulnerable
  implicit_pkgs = fetch_from_lock_file
  vulnerable_pkgs = VulnerabilityFinder.new(@dir, implicit_pkgs).run
  pkgs = NpmMetaData.new(vulnerable_pkgs).fetch
  DuplicatePackageMerger.new(pkgs).run
end