Last active
January 24, 2020 10:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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