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: Dir.pwd) ⇒ 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: Dir.pwd)
  @advisories = advisories
  @dir = dir
  scan_lockfile
end

Instance Method Details

#scan_lockfileObject



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

def scan_lockfile
  lockfile = nil
  Dir.chdir(@dir) do
    lockfile = Bundler::LockfileParser.new(Bundler.read_file('Gemfile.lock'))
  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