Class: Bundler::Audit::Report

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bundler/audit/report.rb

Overview

Represents the result of a scan.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results = []) ⇒ Report

Initializes the report.

Parameters:

  • results (#each) (defaults to: [])


45
46
47
48
49
50
51
52
53
54
# File 'lib/bundler/audit/report.rb', line 45

def initialize(results=[])
  @version    = VERSION
  @created_at = Time.now

  @results = []
  @insecure_sources = []
  @unpatched_gems = []

  results.each { |result| self << result }
end

Instance Attribute Details

#created_atTime (readonly)

The time when the report was generated.

Returns:

  • (Time)


23
24
25
# File 'lib/bundler/audit/report.rb', line 23

def created_at
  @created_at
end

#insecure_sourcesArray<Results::InsecureSources> (readonly)

The insecure sources results.

Returns:

  • (Array<Results::InsecureSources>)


33
34
35
# File 'lib/bundler/audit/report.rb', line 33

def insecure_sources
  @insecure_sources
end

#resultsArray<Results::Result> (readonly)

The list of all results.

Returns:



28
29
30
# File 'lib/bundler/audit/report.rb', line 28

def results
  @results
end

#unpatched_gemsArray<Results::UnpatchedGems> (readonly)

The unpatched gems results.

Returns:

  • (Array<Results::UnpatchedGems>)


38
39
40
# File 'lib/bundler/audit/report.rb', line 38

def unpatched_gems
  @unpatched_gems
end

#versionString (readonly)

The version of bundler-audit which created the report object.

Returns:

  • (String)


18
19
20
# File 'lib/bundler/audit/report.rb', line 18

def version
  @version
end

Instance Method Details

#<<(result) ⇒ Object

Appends a result to the report.

Parameters:

  • result (InsecureSource, UnpatchedGem)


74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/bundler/audit/report.rb', line 74

def <<(result)
  @results << result

  case result
  when Results::InsecureSource
    @insecure_sources << result
  when Results::UnpatchedGem
    @unpatched_gems << result
  end

  return self
end

#advisoriesArray<Advisory>

Returns:



112
113
114
# File 'lib/bundler/audit/report.rb', line 112

def advisories
  @unpatched_gems.map(&:advisory)
end

#each {|result| ... } ⇒ Enumerator

Enumerates over the results.

Yields:

  • (result)

Yield Parameters:

Returns:

  • (Enumerator)


65
66
67
# File 'lib/bundler/audit/report.rb', line 65

def each(&block)
  @results.each(&block)
end

#each_advisory {|advisory| ... } ⇒ Enumerator

Yields:

  • (advisory)

Yield Parameters:

Returns:

  • (Enumerator)


103
104
105
106
107
# File 'lib/bundler/audit/report.rb', line 103

def each_advisory
  return enum_for(__method__) unless block_given?

  @unpatched_gems.each { |result| yield result.advisory }
end

#each_vulnerable_gem {|gem| ... } ⇒ Enumerator

Yields:

  • (gem)

Yield Parameters:

  • (Gem::Specification)

Returns:

  • (Enumerator)


123
124
125
126
127
# File 'lib/bundler/audit/report.rb', line 123

def each_vulnerable_gem
  return enum_for(__method__) unless block_given?

  @unpatched_gems.each { |result| yield result.gem }
end

#to_hHash{Symbol => Object}

Returns:

  • (Hash{Symbol => Object})


139
140
141
142
143
144
145
# File 'lib/bundler/audit/report.rb', line 139

def to_h
  {
    version:    @version,
    created_at: @created_at,
    results:    @results.map(&:to_h)
  }
end

#vulnerable?Boolean

Determines if there were vulnerabilities found.

Returns:

  • (Boolean)


92
93
94
# File 'lib/bundler/audit/report.rb', line 92

def vulnerable?
  !@results.empty?
end

#vulnerable_gemsArray<Gem::Specification>

Returns:

  • (Array<Gem::Specification>)


132
133
134
# File 'lib/bundler/audit/report.rb', line 132

def vulnerable_gems
  @unpatched_gems.map(&:gem)
end