Sha256: d3257639e456dcaeeb87658f4f8dfb5a992cc22c49e47f8b25750f76438c6e17

Contents?: true

Size: 893 Bytes

Versions: 12

Compression:

Stored size: 893 Bytes

Contents

#
# 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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hrw-0.3.9 lib/hrw/scanner/gemfile.rb
hrw-0.3.8 lib/hrw/scanner/gemfile.rb
hrw-0.3.7 lib/hrw/scanner/gemfile.rb
hrw-0.3.6 lib/hrw/scanner/gemfile.rb
hrw-0.3.5 lib/hrw/scanner/gemfile.rb
hrw-0.3.4 lib/hrw/scanner/gemfile.rb
hrw-0.3.3 lib/hrw/scanner/gemfile.rb
hrw-0.3.2 lib/hrw/scanner/gemfile.rb
hrw-0.3.1 lib/hrw/scanner/gemfile.rb
hrw-0.3.0 lib/hrw/scanner/gemfile.rb
hrw-0.2.3 lib/hrw/scanner/gemfile.rb
hrw-0.2.2 lib/hrw/scanner/gemfile.rb