require_relative 'base' require 'active_support/core_ext/string/strip' require 'erubis' namespace :version do desc 'bump version of library to new version' task :bump do new_version = ENV['VERSION'] || ENV['version'] raise Exception, "You need to define a version via \"VERSION=\" or \"version=\"." raw_module_names = File.open(version_file, "r").readlines.grep(/module/) module_names = raw_module_names.collect { |n| n.chomp.match(/module\s+(\S+)/) {$1} } template = <<-EOF #main <%= @modules.first %> <% @modules.each do |m| %> module <%= m %> <% end %> VERSION = '<%= @version %>' <% @modules.size.times do |m| %> end <% end %> EOF version_string = Erubis::Eruby.new(template).evaluate(modules: module_names, version: new_version) File.open(version_file, "w") do |f| f.write version_string.strip_heredoc end sh "git add #{version_file}" sh "git commit -m 'version bump to #{new_version}'" end end