Module: PoiseBoiler::Helpers::Rake::BumpHelpers Private
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Helper methods for bumping gem versions.
Constant Summary collapse
- VERSION_CONST =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/(^\s*VERSION = ['"])([^'"]+)(['"]\s*$)/
Instance Method Summary collapse
- #bump_version!(type: :patch, release: false, &block) ⇒ Object private
- #bumped_version(type: :patch, release: false) ⇒ Object private
- #find_version_rb ⇒ Object private
- #latest_tag ⇒ Object private
Instance Method Details
#bump_version!(type: :patch, release: false, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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 ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 68 |
# 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 ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/poise_boiler/helpers/rake/bump.rb', line 32 def latest_tag git = Git.open(base) if git..empty? nil else tag_name = git..last.name if tag_name =~ /^v(.*)$/ $1 else tag_name end end end |