class Bumpversion::BumpString

Public Class Methods

new(options) click to toggle source
# File lib/bumpversion/bump_string.rb, line 3
def initialize(options)
  @options = options
end

Public Instance Methods

bump() click to toggle source
# File lib/bumpversion/bump_string.rb, line 41
def bump
  unless @options[:new_version]
    actual_version = matched.named_captures.reject { |k,v| v.nil? }.map { |k, v| [k.to_sym, v.to_i] }.to_h
    matched_version = update_version(actual_version)
    new_version = pattern_replace.match(@options[:current_version]).named_captures.map do |k, v|
      dictionary.include?(k.to_sym) ? "#{matched_version[k.to_sym]}" : v || ""
    end.join("")
    @options[:new_version] = new_version
  end
  @options
end
dictionary() click to toggle source
# File lib/bumpversion/bump_string.rb, line 7
def dictionary
  %w[major minor patch build].map { |k| k.to_sym }
end
key_part() click to toggle source
# File lib/bumpversion/bump_string.rb, line 11
def key_part
  @options[:part].to_sym
end
matched() click to toggle source
# File lib/bumpversion/bump_string.rb, line 23
def matched
  @match ||= pattern.match(@options[:current_version])
end
pattern() click to toggle source
# File lib/bumpversion/bump_string.rb, line 15
def pattern
  /(?<major>\d+).(?<minor>\d+).(?<patch>\d+).?(?<build>\d+)?/
end
pattern_replace() click to toggle source
# File lib/bumpversion/bump_string.rb, line 19
def pattern_replace
  /(?<major>\d+)(?<a>.)(?<minor>\d+)(?<b>.)(?<patch>\d+)(?<c>.)?(?<build>\d+)?/
end
update_version(matched_version) click to toggle source
# File lib/bumpversion/bump_string.rb, line 27
def update_version(matched_version)
  bumped = false
  matched_version.each do | part, number |
    matched_version[part] = 0 if bumped && part.to_sym != :build

    if part.to_sym == key_part || part.to_sym == :build
      matched_version[part] += 1
      bumped = true
    end
  end

  matched_version
end