Class: Bundler::Advise::GemAdviser
- Inherits:
-
Object
- Object
- Bundler::Advise::GemAdviser
- Defined in:
- lib/bundler/advise/gem_adviser.rb
Instance Method Summary collapse
-
#initialize(advisories: Advisories.new, dir: nil) ⇒ GemAdviser
constructor
A new instance of GemAdviser.
- #scan_lockfile ⇒ Object
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_lockfile ⇒ Object
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 |