max
max

Reputation: 102026

How to allow a wide range of Rails versions for a gem

I'm the author of pretty simple Rails engine gem that basically just consists of a helper and a bit of javascript.

The only real runtime dependency is jquery-rails.

Hopefully it should pretty much be compatible with any Rails version > 5. As I originally wrote the gem I used a pragmatic squiggly arrow.

s.add_dependency 'rails', '~> 5.0.0', '>= 5.0.0.1'

Which was pretty foolish since it does not work with 5.1+. I now changed it to an open requirement ">= 5.0" and gem build warns that its not advisable:

WARNING:  open-ended dependency on rails (>= 5.0) is not recommended
  if rails is semantically versioned, use:
    add_runtime_dependency 'rails', '~> 5.0'

Whats the best practice in terms of minimising maintenance and ensuring decent compatibility?

Should I declare the Rails dependency as a development_dependency since its implied that the gem is mounted in rails engine?

Upvotes: 0

Views: 253

Answers (1)

jacobherrington
jacobherrington

Reputation: 463

The suggestion in the warning is good advice.

s.add_dependency 'rails', '~> 5.0' This would mean it's fine for Rails 5.x, but not for 6.x.

Upvotes: 1

Related Questions