Rakefile in metatron-0.4.2 vs Rakefile in metatron-0.5.0

- old
+ new

@@ -14,6 +14,38 @@ desc "allows running a demo controller" task :demo do system("rackup --host 0.0.0.0 -P #{File.expand_path(".")}/tmp/daemon.pid") end +desc "automatically bump the gem's version" +task :bump, [:type] do |_t, args| + type = args[:type] || ENV["TYPE"] || "patch" + current_version = Metatron::VERSION + new_version = calculate_new_version(type) + puts "Bumping gem version from #{current_version} to #{new_version}" + update_version(new_version) +end + task default: %i[spec rubocop yard] + +def calculate_new_version(type) + version = Metatron::VERSION.split(".").map(&:to_i) + case type + when "patch" + version[2] += 1 + when "minor" + version[1] += 1 + version[2] = 0 + when "major" + version[0] += 1 + version[1] = 0 + version[2] = 0 + end + + version.join(".") +end + +def update_version(new_version) + file = File.read("lib/metatron/version.rb") + new_contents = file.gsub(/VERSION = "(.+)"/, %(VERSION = "#{new_version}")) + File.write("lib/metatron/version.rb", new_contents) +end