module PoiseBoiler::Helpers::Rake::BumpHelpers
Helper methods for bumping gem versions.
@api private @since 1.2.0
Constants
- VERSION_CONST
Public Instance Methods
bump_version!(type: :patch, release: false, &block)
click to toggle source
# File lib/poise_boiler/helpers/rake/bump.rb, line 70 def bump_version!(type: :patch, release: false, &block) version_rb_path = find_version_rb raise "Unable to find a version.rb in #{base}" unless version_rb_path shell.say("Bumping version in #{version_rb_path}") if ENV['DEBUG'] content = IO.read(version_rb_path) raise "Unable to find current version in #{version_rb_path}" unless VERSION_CONST =~ content current_version = $2 version = bumped_version(type: type, release: release) shell.say("Bumping gem version from #{current_version} to #{version}") new_content = content.gsub(VERSION_CONST, "\\1#{version}\\3") IO.write(version_rb_path, new_content) begin block.call if block rescue Exception # Restore the original version if anything goes wrong. IO.write(version_rb_path, content) raise end end
bumped_version(type: :patch, release: false)
click to toggle source
# File lib/poise_boiler/helpers/rake/bump.rb, line 46 def bumped_version(type: :patch, release: false) current_version = latest_tag next_version = if current_version parts = current_version.split(/\./).map(&:to_i) bump_index = {major: 0, minor: 1, patch: 2}[type] parts[bump_index] += 1 (bump_index+1..2).each {|n| parts[n] = 0 } parts.map(&:to_s).join('.') else '1.0.0' end # Release mode means plain, otherwise .pre. if release next_version else next_version + '.pre' end end
find_version_rb()
click to toggle source
# File lib/poise_boiler/helpers/rake/bump.rb, line 65 def find_version_rb candidates = Dir[File.join(base, 'lib', '**', 'version.rb')] candidates.min_by {|path| path.size } end
latest_tag()
click to toggle source
# File lib/poise_boiler/helpers/rake/bump.rb, line 32 def latest_tag git = Git.open(base) if git.tags.empty? nil else tag_name = git.tags.last.name if tag_name =~ /^v(.*)$/ $1 else tag_name end end end