class Bundler::Audit::Database


and CVE number.
Represents the directory of advisories, grouped by gem name

def self.download(options={})

Other tags:
    Since: - 0.8.0

Other tags:
    Note: -

Raises:
  • (DownloadFailed) -

Returns:
  • (Dataase) -

Options Hash: (**options)
  • :quiet (Boolean) --
  • :path (String) --

Parameters:
  • options (Hash) --
def self.download(options={})
  unless (options.keys - [:path, :quiet]).empty?
    raise(ArgumentError,"Invalid option(s)")
  end
  path = options.fetch(:path,DEFAULT_PATH)
  command = %w(git clone)
  command << '--quiet' if options[:quiet]
  command << URL << path
  unless system(*command)
    raise(DownloadFailed,"failed to download #{URL} to #{path.inspect}")
  end
  return new(path)
end

def self.exists?(path=DEFAULT_PATH)

Other tags:
    Since: - 0.8.0

Returns:
  • (Boolean) -

Parameters:
  • path (String) --
def self.exists?(path=DEFAULT_PATH)
  File.directory?(path) && !(Dir.entries(path) - %w[. ..]).empty?
end

def self.path

Returns:
  • (String) -
def self.path
  DEFAULT_PATH
end

def self.update!(options={})

Deprecated:
  • Use {#update!} instead.

Other tags:
    Since: - 0.3.0

Other tags:
    Note: -

Raises:
  • (ArgumentError) -

Returns:
  • (Boolean, nil) -

Options Hash: (**options)
  • :quiet (Boolean) --

Parameters:
  • options (Hash) --
def self.update!(options={})
  raise "Invalid option(s)" unless (options.keys - [:quiet]).empty?
  if File.directory?(DEFAULT_PATH)
    begin
      new(DEFAULT_PATH).update!(options)
    rescue UpdateFailed then false
    end
  else
    begin
      download(options.merge(path: DEFAULT_PATH))
    rescue DownloadFailed then false
    end
  end
end

def advisories(&block)

Returns:
  • (Enumerator) -

Other tags:
    Yieldparam: advisory -

Other tags:
    Yield: -
def advisories(&block)
  return enum_for(__method__) unless block_given?
  each_advisory_path do |path|
    yield Advisory.load(path)
  end
end

def advisories_for(name)

Returns:
  • (Enumerator) -

Other tags:
    Yieldparam: advisory -

Other tags:
    Yield: -

Parameters:
  • name (String) --
def advisories_for(name)
  return enum_for(__method__,name) unless block_given?
  each_advisory_path_for(name) do |path|
    yield Advisory.load(path)
  end
end

def check_gem(gem)

Returns:
  • (Enumerator) -

Other tags:
    Yieldparam: advisory -

Other tags:
    Yield: -

Parameters:
  • gem (Gem::Specification) --
def check_gem(gem)
  return enum_for(__method__,gem) unless block_given?
  advisories_for(gem.name) do |advisory|
    if advisory.vulnerable?(gem.version)
      yield advisory
    end
  end
end

def each_advisory_path(&block)

Other tags:
    Yieldparam: path -

Other tags:
    Yield: -
def each_advisory_path(&block)
  Dir.glob(File.join(@path,'gems','*','*.yml'),&block)
end

def each_advisory_path_for(name,&block)

Other tags:
    Yieldparam: path -

Other tags:
    Yield: -

Parameters:
  • name (String) --
def each_advisory_path_for(name,&block)
  Dir.glob(File.join(@path,'gems',name,'*.yml'),&block)
end

def git?

Other tags:
    Since: - 0.8.0

Returns:
  • (Boolean) -
def git?
  File.directory?(File.join(@path,'.git'))
end

def initialize(path=self.class.path)

Raises:
  • (ArgumentError) -

Parameters:
  • path (String) --
def initialize(path=self.class.path)
  unless File.directory?(path)
    raise(ArgumentError,"#{path.dump} is not a directory")
  end
  @path = path
end

def inspect

Returns:
  • (String) -
def inspect
  "#<#{self.class}:#{self}>"
end

def last_updated_at

Other tags:
    Since: - 0.8.0

Returns:
  • (Time) -
def last_updated_at
  if git?
    Dir.chdir(@path) do
      Time.parse(`git log --date=iso8601 --pretty="%cd" -1`)
    end
  else
    File.mtime(@path)
  end
end

def size

Returns:
  • (Integer) -
def size
  each_advisory_path.count
end

def to_s

Returns:
  • (String) -
def to_s
  @path
end

def update!(options={})

Other tags:
    Since: - 0.8.0

Returns:
  • (true, nil) -

Options Hash: (**options)
  • :quiet (Boolean) --

Parameters:
  • options (Hash) --
def update!(options={})
  if git?
    Dir.chdir(@path) do
      command = %w(git pull)
      command << '--quiet' if options[:quiet]
      command << 'origin' << 'master'
      unless system(*command)
        raise(UpdateFailed,"failed to update #{@path.inspect}")
      end
      return true
    end
  end
end