Sha256: 5ad5100744ce4a638a99cb1c0ecda9cd295c486324000706c1fb0313df91ae54

Contents?: true

Size: 821 Bytes

Versions: 4

Compression:

Stored size: 821 Bytes

Contents

# frozen_string_literal: true

require "bundler"
require "bundled_gem/version"

module BundledGem
  # default bundler lockfile
  LOCKFILE = "Gemfile.lock"

  class LockfileReader
    def initialize(lockfile: LOCKFILE)
      abort "No such file: #{lockfile}" unless File.exist?(lockfile)
      @lockfile_content = File.read(lockfile)
    end

    # Parse `Gemfile.lock` and Retrieve specs
    def lockfile_specs
      lockfile.specs
    end

    # Get version info from `Gemfile.lock`
    def get_version(gem)
      lockfile_specs.find { |s| s.name == gem }&.version
    end

    # Check gem is listed in `Gemfile.lock`
    def gem_listed?(gem)
      lockfile_specs.map(&:name).include? gem
    end

    private
      def lockfile
        @lockfile ||= ::Bundler::LockfileParser.new(@lockfile_content)
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bundled_gems-1.1.0 lib/bundled_gems.rb
bundled_gems-1.0.0 lib/bundled_gems.rb
bundled_gems-0.2.0 lib/bundled_gems.rb
bundled_gems-0.1.0 lib/bundled_gems.rb