class Bundler::Advise::Advisories

Attributes

dir[R]
repo[R]

Public Class Methods

new(dir: File.expand_path('~/.ruby-advisory-db'), repo: 'https://github.com/rubysec/ruby-advisory-db.git') click to toggle source
# File lib/bundler/advise/advisories.rb, line 7
def initialize(dir: File.expand_path('~/.ruby-advisory-db'),
               repo: 'https://github.com/rubysec/ruby-advisory-db.git')
  @dir = dir
  @repo = repo
end

Public Instance Methods

clean_update!() click to toggle source
# File lib/bundler/advise/advisories.rb, line 26
def clean_update!
  FileUtils.rmtree @dir
  update
end
dir_missing_or_empty() click to toggle source
# File lib/bundler/advise/advisories.rb, line 22
def dir_missing_or_empty
  !File.exist?(@dir) || Dir.empty?(@dir)
end
gem_advisories_for(gem_name) click to toggle source
# File lib/bundler/advise/advisories.rb, line 31
def gem_advisories_for(gem_name)
  # Sorting the results isn't strictly needed but provides deterministic
  # results for testing.
  Dir[File.join(@dir, 'gems', gem_name, '*.yml')].sort.map do |ad_yml|
    Advisory.from_yml(ad_yml)
  end
end
update() click to toggle source
# File lib/bundler/advise/advisories.rb, line 13
def update
  dir_missing_or_empty ? clone : pull
rescue ArgumentError => e
  # git gem is dorky in this case, putting the path into the backtrace.
  msg = "Unexpected problem with working dir for advisories: #{e.message} #{e.backtrace}.\n" +
    "Call clean_update! to remove #{@dir} and re-clone it."
  raise RuntimeError, msg
end

Private Instance Methods

clone() click to toggle source
# File lib/bundler/advise/advisories.rb, line 41
def clone
  Git.clone(@repo, @dir)
end
pull() click to toggle source
# File lib/bundler/advise/advisories.rb, line 45
def pull
  # git gem uses --git-dir and --work-tree so this SHOULD work when OS working dir
  # doesn't match - but that's not always true, so let's ensure this works on all
  # CI boxen out there.
  Dir.chdir(@dir) do
    git = Git.open(@dir)
    git.pull
  end
end