Class: Legendary::Vulnerabilities

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/legendary/vulnerabilities.rb

Instance Method Summary collapse

Constructor Details

#initialize(info) ⇒ Vulnerabilities

Returns a new instance of Vulnerabilities.



5
6
7
# File 'lib/legendary/vulnerabilities.rb', line 5

def initialize(info)
  @info = info
end

Instance Method Details

#eachObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/legendary/vulnerabilities.rb', line 18

def each
  return nil unless exists?

  Dir.foreach(path) do |yaml_file|
    next if yaml_file =~ /\A\./

    info = YAML.load(File.read(File.join(path, yaml_file)))

    satisfied_version = lambda do |version|
      Gem::Requirement.new(version.split(',')).satisfied_by?(@info.version)
    end

    is_affected = (info["patched_versions"] || []).none?(&satisfied_version)
    not_patched = (info["unaffected_versions"] || []).none?(&satisfied_version)

    if is_affected && not_patched
      yield info
    end
  end
end

#exists?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/legendary/vulnerabilities.rb', line 14

def exists?
  File.exists?(path)
end

#pathObject



9
10
11
12
# File 'lib/legendary/vulnerabilities.rb', line 9

def path
  @path ||= File.join(Legendary.repository.path,
                      "/gems/#{@info.name}")
end