#!/usr/bin/env rake require "bundler/gem_tasks" require 'rainbow/ext/string' ## begin version management def valid? version pattern = /^\d+\.\d+\.\d+(\-(dev|beta|rc\d+))?$/ raise "Tried to set invalid version: #{version}".color(: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.".color(: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.".color(: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 <