10

I'm trying to modify a gem which currently has a dependency on activeresource defined as:

s.add_dependency              "activeresource", "~> 3.0"

In order to get the gem working with Rails 4, I need to extend the dependency to work with either version 3 or 4 of activeresource. I don't want to simply add the following as it could cause problems later:

s.add_dependency              "activeresource", ">= 3.0"

Is there a way to specify a list of acceptable versions? ~> 3.0 or ~> 4.0?

Simmo
  • 1,717
  • 19
  • 37
  • I would personally say pick one and stick with it – Dan May 07 '14 at 16:58
  • 2
    `s.add_dependency "activeresource", ">= 3.0", "< 5.0"` is simplest I can think of. Of course you will need to detect when version is loaded and abstract differences away in the gem, which could be hard. I'd say just start a new major version of the gem and use the later dependency in it. You can still support both versions by releasing minor updates in parallel (if you really care to do so), but you won't pollute your code with run-time determinations of which `activerecord` engine you are working with – Neil Slater May 07 '14 at 17:01

2 Answers2

10

Accordly to the documentation, if you want to have all version between 3 and 4, you can do this :

s.add_dependency "activeresource", ">= 3.0", "< 5.0"

The specifier accepted are : >=, ~>, <=, >, <.

Dougui
  • 7,142
  • 7
  • 52
  • 87
3

I think you should write it with < 5.x, because this will prevent beta versions like 5.0.beta1 to be installed.

 s.add_dependency "activeresource", ">= 3.0", "< 5.x"

Because with < 5.0, 5.0.beta1 can be installed - 5.0.beta1 is smaller than 5.0.

Markus
  • 5,667
  • 4
  • 48
  • 64