Skip to content

Instantly share code, notes, and snippets.

@fabdbt
Last active January 24, 2020 10:49
Show Gist options
  • Save fabdbt/17d88a60f13d5d3b7a195afc4e806dea to your computer and use it in GitHub Desktop.
Save fabdbt/17d88a60f13d5d3b7a195afc4e806dea to your computer and use it in GitHub Desktop.
Ruby script that returns version of a gem included in `Gemfile.lock` file
#!/usr/bin/env ruby
require 'bundler'
puts Bundler::LockfileParser.new(Bundler.read_file(Bundler.default_lockfile)).specs.find { |s| s.name == ARGV[0] }.version.version
# Requires `Gemfile.lock` file with required dependency included (eg: `bundle install rubocop`)
# Use case : gem install rubocop -v $(ruby bundler_version.rb rubocop) --no-document
# Can be useful in CI jobs (do not install all dependencies through `bundle install` when you only need to pass linter for example)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment