Class: GemDigest::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_digest/analyzer.rb

Instance Method Summary collapse

Constructor Details

#initialize(gemfile_lock_path = "Gemfile.lock") ⇒ Analyzer

Returns a new instance of Analyzer.

Raises:



10
11
12
13
# File 'lib/gem_digest/analyzer.rb', line 10

def initialize(gemfile_lock_path = "Gemfile.lock")
  @gemfile_lock_path = gemfile_lock_path
  raise Error, "Gemfile.lock not found at #{gemfile_lock_path}" unless File.exist?(gemfile_lock_path)
end

Instance Method Details

#analyzeObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gem_digest/analyzer.rb', line 15

def analyze
  lockfile = Bundler::LockfileParser.new(File.read(@gemfile_lock_path))
  gems_data = []

  lockfile.specs.each do |spec|
    latest_version = fetch_latest_version(spec.name)
    next unless latest_version

    gems_data << {
      name: spec.name,
      current_version: spec.version.to_s,
      latest_version: latest_version,
      source: spec.source&.to_s || "rubygems"
    }
  end

  gems_data
end