Where do you store your Rails Application's version number?
My strategy is to let your VCS tags do it for you (git shown here).
Add this to your application.rb
:
# Only attempt update on local machine
if Rails.env.development?
# Update version file from latest git tag
File.open('config/version', 'w') do |file|
file.write `git describe --tags --always` # or equivalent
end
end
config.version = File.read('config/version')
You can then access the version anywhere in your app with Rails.configuration.version
I don't really think there's any convention for this. I guess it's all about what seems natural to you.
Some places the version number can be placed are in:
config/environment.rb
config/application.rb
config/initializers/version.rb
by adding:
VERSION = '1.0.0'
Regardless of which option you choose (from above) - the VERSION constant will be set at the initialization of the app.
For my blog I just update the footer of my layout - as the version number isn't used anywhere else.
The lib
-folder does sound a bit strange though, as this folder is meant to store re-usable modules.
My preference is to create a rake task that generates
# config/initializers/version.rb
VERSION = ["1", "0", "f3d9da7"]
FWIW, my rake task:
task :create_version do
desc "create VERSION. Use MAJOR_VERSION, MINOR_VERSION, BUILD_VERSION to override defaults"
version_file = "#{Rails.root}/config/initializers/version.rb"
major = ENV["MAJOR_VERSION"] || 1
minor = ENV["MINOR_VERSION"] || 0
build = ENV["BUILD_VERSION"] || `git describe --always --tags`
version_string = "VERSION = #{[major.to_s, minor.to_s, build.strip]}\n"
File.open(version_file, "w") {|f| f.print(version_string)}
$stderr.print(version_string)
end