Class: Bundler::Advise::GemAdviser

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/advise/gem_adviser.rb

Instance Method Summary collapse

Constructor Details

#initialize(advisories: Advisories.new, dir: nil) ⇒ GemAdviser

Returns a new instance of GemAdviser.



5
6
7
8
9
# File 'lib/bundler/advise/gem_adviser.rb', line 5

def initialize(advisories: Advisories.new, dir: nil)
  @advisories = advisories
  @dir = dir
  scan_lockfile
end

Instance Method Details

#scan_lockfileObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bundler/advise/gem_adviser.rb', line 11

def scan_lockfile
  lockfile = nil
  begin
    restore = ENV['BUNDLE_GEMFILE']
    ENV['BUNDLE_GEMFILE'] = File.join(@dir, 'Gemfile') if @dir
    lockfile = Bundler::LockfileParser.new(Bundler.read_file(Bundler.default_lockfile))
  ensure
    # restoration is probably overkill, but need to retain prior functionality
    ENV['BUNDLE_GEMFILE'] = restore
  end
  lockfile.specs.map do |spec|
    @advisories.gem_advisories_for(spec.name).select do |ad|
      ad.is_affected?(spec.version).tap { |res| ad.send(:gem_spec=, spec) if res }
    end
  end.flatten
end