Simply Business homepage
  • Business insurance

    • Business Insurance FAQs

    Business insurance covers

  • Support
  • Claims
  • Sign In
Call Us0333 0146 683
Chat With UsChat support 24/7
Tech blog

Block a specific gem version in your Gemfile in Bundler

1-minute read

Lukas Oberhuber

Lukas Oberhuber

21 November 2017

Share on FacebookShare on TwitterShare on LinkedIn

If you ever want to exclude or block a specific version of a gem in Bundler, you can.

The syntax for excluding a particular gem version in bundler is super simple:

gem 'gemname', '!= 1.0.1'

This is most useful if you have a gem version that is broken and you want to exclude it, but don't want to exclude all upgrades. A typical Gemfile using this might look like:

gem 'gemname', ['~> 1.0', '!= 1.0.1']

This will allow any versions of gemname in the 1.x.x series, except for 1.0.1.

When the maintainers of gemname incorporate a fix (hopefully based on your pull request and release gemname 1.0.2, you can quickly update your Gemfile.lock by running bundle update gemname. It will automatically stop the upgrade until there is a version after 1.0.1.

Here's the code in Bundler that defines the DSL in lib/bundler/version_ranges.rb in version 1.16:

ranges = requirement.requirements.map do |op, v|
  case op
  when "=" then ReqR.new(ReqR::Endpoint.new(v, true), ReqR::Endpoint.new(v, true))
  when "!=" then NEq.new(v)
  when ">=" then ReqR.new(ReqR::Endpoint.new(v, true), ReqR::Endpoint.new(ReqR::INFINITY, false))
  when ">" then ReqR.new(ReqR::Endpoint.new(v, false), ReqR::Endpoint.new(ReqR::INFINITY, false))
  when "<" then ReqR.new(ReqR::Endpoint.new(ReqR::ZERO, true), ReqR::Endpoint.new(v, false))
  when "<=" then ReqR.new(ReqR::Endpoint.new(ReqR::ZERO, true), ReqR::Endpoint.new(v, true))
  when "~>" then ReqR.new(ReqR::Endpoint.new(v, true), ReqR::Endpoint.new(v.bump, false))
  else raise "unknown version op #{op} in requirement #{requirement}"
  end
end.uniq

{: data-start="46"}

This feature is undocumented in bundler, so thought it worth highlighting briefly.

Ready to start your career at Simply Business?

Want to know more about what it's like to work in tech at Simply Business? Read about our approach to tech, then check out our current vacancies.

Find out more

We create this content for general information purposes and it should not be taken as advice. Always take professional advice. Read our full disclaimer

Find this article useful? Spread the word.

Share on Facebook
Share on Twitter
Share on LinkedIn

Keep up to date with Simply Business. Subscribe to our monthly newsletter and follow us on social media.

Subscribe to our newsletter

Insurance

Public liability insuranceBusiness insuranceProfessional indemnity insuranceEmployers’ liability insuranceLandlord insuranceTradesman insuranceSelf-employed insuranceRestaurant insuranceVan insuranceInsurers

Address

6th Floor99 Gresham StreetLondonEC2V 7NG

Northampton 900900 Pavilion DriveNorthamptonNN4 7RG

© Copyright 2024 Simply Business. All Rights Reserved. Simply Business is a trading name of Xbridge Limited which is authorised and regulated by the Financial Conduct Authority (Financial Services Registration No: 313348). Xbridge Limited (No: 3967717) has its registered office at 6th Floor, 99 Gresham Street, London, EC2V 7NG.