It is common to have a version.rb file, defining the version of the gem, like:
module Foo
VERSION = "0.0.1"
end
and in the .gemspec file, require the version.rb and use Foo::VERSION there.
What is the benefit of this convention?
--
Also, sometime when namespace is used, the generated verison file can be deeply in nested folders. Wouldn't it be easier to place a version.rb directly under lib/ and specifying the version there?
So It all started in 2006 when RubyGems created Gemspec to define Ruby package specifications. Gemspec is basically the Readme for gems. It tells you about the author, version, summary, description, internal dependencies, execution and everything about the Gem.
If this is the case, you can look on /usr/lib/ruby/gems/1.8/gems/rubygems-update-x.x.x and take the directory with the highest value of x.x.x.
Updating a Gem Without Modifying the Gemfile This command will update rack-cache and its dependencies to the latest version allowed by the Gemfile (in this case, the latest version available). It will not modify any other dependencies.
This is done this way to reduce churn (change rate) on .gemspec file. I imagine that dependency changes are much more important than version bumps (which are also more frequent). So version changes would add too much noise and hide important commits.
It depends on what gem builder you used. Having a separate file makes it easy to stomp and rebuild as you bump version numbers with rake
tasks, for example. this is a lot easier than fiddling with a source file and trying not to damage anything.
Some packagers use a separate VERSION
file.
In short, if your gem doesn't need to know the current version itself, then you don't need a version.rb
. Even some of the well-known gems like rack
don't use it.
Let's say you are building an executable gem that contains an option -v
to see the current version, or you have to print current version to warn developers there are some deprecated changes, then to require
a separated version file is much more convenient and efficient than parse the gemspec.
It's just a convention in Ruby community. The main reason of why version.rb
is everywhere is that lots of gems are built by bundler gem
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With