class Bundler::Plumber::Database
Represents the directory of advisories, grouped by gem name and CVE number.
Constants
- URL
Git
URL
of the ruby-mem-advisory-db- USER_PATH
Path to the user's copy of the ruby-mem-advisory-db
- VENDORED_PATH
Default path to the ruby-mem-advisory-db
- VENDORED_TIMESTAMP
Timestamp for when the database was last updated
Attributes
The path to the advisory database
Public Class Methods
Initializes the Advisory
Database
.
@param [String] path
The path to the advisory database.
@raise [ArgumentError]
The path was not a directory.
# File lib/bundler/plumber/database.rb, line 56 def initialize(path=self.class.path) unless File.directory?(path) raise(ArgumentError,"#{path.dump} is not a directory") end @path = path end
The default path for the database.
@return [String]
The path to the database directory.
# File lib/bundler/plumber/database.rb, line 70 def self.path if File.directory?(USER_PATH) t1 = Dir.chdir(USER_PATH) { Time.parse(`git log --date=iso8601 --pretty="%cd" -1`) } t2 = VENDORED_TIMESTAMP if t1 >= t2 USER_PATH else VENDORED_PATH end else VENDORED_PATH end end
Updates the ruby-mem-advisory-db.
@param [Boolean, quiet]
Specify whether `git` should be `--quiet`.
@return [Boolean, nil]
Specifies whether the update was successful. A `nil` indicates no update was performed.
@note
Requires network access.
# File lib/bundler/plumber/database.rb, line 98 def self.update!(options={}) raise "Invalid option(s)" unless (options.keys - [:quiet]).empty? if File.directory?(USER_PATH) if File.directory?(File.join(USER_PATH, ".git")) Dir.chdir(USER_PATH) do command = "git fetch --all; git reset --hard origin/master" command << ' --quiet' if options[:quiet] system *command end end else command = %w(git clone) command << '--quiet' if options[:quiet] command << URL << USER_PATH system *command end end
Public Instance Methods
Enumerates over every advisory in the database.
@yield [advisory]
If a block is given, it will be passed each advisory.
@yieldparam [Advisory] advisory
An advisory from the database.
@return [Enumerator]
If no block is given, an Enumerator will be returned.
# File lib/bundler/plumber/database.rb, line 129 def advisories(&block) return enum_for(__method__) unless block_given? each_advisory_path do |path| yield Advisory.load(path) end end
Enumerates over advisories for the given gem.
@param [String] name
The gem name to lookup.
@yield [advisory]
If a block is given, each advisory for the given gem will be yielded.
@yieldparam [Advisory] advisory
An advisory for the given gem.
@return [Enumerator]
If no block is given, an Enumerator will be returned.
# File lib/bundler/plumber/database.rb, line 152 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
Verifies whether the gem is effected by any advisories.
@param [Gem::Specification] gem
The gem to verify.
@yield [advisory]
If a block is given, it will be passed advisories that effect the gem.
@yieldparam [Advisory] advisory
An advisory that effects the specific version of the gem.
@return [Enumerator]
If no block is given, an Enumerator will be returned.
# File lib/bundler/plumber/database.rb, line 176 def check_gem(gem) return enum_for(__method__,gem) unless block_given? advisories_for(gem.name) do |advisory| if advisory.leaky?(gem.version) yield advisory end end end
Inspects the database.
@return [String]
The inspected database.
# File lib/bundler/plumber/database.rb, line 212 def inspect "#<#{self.class}:#{self}>" end
The number of advisories within the database.
@return [Integer]
The number of advisories.
# File lib/bundler/plumber/database.rb, line 192 def size each_advisory_path.count end
Converts the database to a String.
@return [String]
The path to the database.
# File lib/bundler/plumber/database.rb, line 202 def to_s @path end
Protected Instance Methods
Enumerates over every advisory path in the database.
@yield [path]
The given block will be passed each advisory path.
@yieldparam [String] path
A path to an advisory `.yml` file.
# File lib/bundler/plumber/database.rb, line 227 def each_advisory_path(&block) Dir.glob(File.join(@path,'gems','*','*.yml'),&block) end
Enumerates over the advisories for the given gem.
@param [String] name
The gem of the gem.
@yield [path]
The given block will be passed each advisory path.
@yieldparam [String] path
A path to an advisory `.yml` file.
# File lib/bundler/plumber/database.rb, line 243 def each_advisory_path_for(name,&block) Dir.glob(File.join(@path,'gems',name,'*.yml'),&block) end