# # Third-party libraries # require 'bundler' require 'bundler/lockfile_parser' module Hrw module Scanner # # Used to scan gem lock file # class Gemfile attr_reader :package_manager # Initialize a scanner # # @param [String] root The path to the project root # @param [String] lockfile # The name for the lock file, default is `Gemfile.lock` def initialize(root = Dir.pwd, lockfile = 'Gemfile.lock') @package_manager = 'rubygems' @root = File.expand_path(root) @lockfile = Bundler::LockfileParser.new( File.read(File.join(@root, lockfile)) ) end # Scan the lock file # @return [Hash] def scan @lockfile.specs.map do |spec| { name: spec.name, version: spec.version.to_s } end end end end end