We use the wonderful semantic versioning paradigm when versioning our rails app. One question I had was where is it best to store this number? I\'ve seen it stored in /l
version.rake
def valid? version
pattern = /^\d+\.\d+\.\d+(\-(dev|beta|rc\d+))?$/
raise "Tried to set invalid version: #{version}".red unless version =~ pattern
end
def correct_version version
ver, flag = version.split '-'
v = ver.split '.'
(0..2).each do |n|
v[n] = v[n].to_i
end
[v.join('.'), flag].compact.join '-'
end
def read_version
begin
File.read 'VERSION'
rescue
raise "VERSION file not found or unreadable.".red
end
end
def write_version version
valid? version
begin
File.open 'VERSION', 'w' do |file|
file.write correct_version(version)
end
rescue
raise "VERSION file not found or unwritable.".red
end
end
def reset current, which
version, flag = current.split '-'
v = version.split '.'
which.each do |part|
v[part] = 0
end
[v.join('.'), flag].compact.join '-'
end
def increment current, which
version, flag = current.split '-'
v = version.split '.'
v[which] = v[which].to_i + 1
[v.join('.'), flag].compact.join '-'
end
desc "Prints the current application version"
version = read_version
task :version do
puts <