Class: Bumpversion::BumpString
- Inherits:
-
Object
- Object
- Bumpversion::BumpString
- Defined in:
- lib/bumpversion/bump_string.rb
Instance Method Summary collapse
- #bump ⇒ Object
- #dictionary ⇒ Object
-
#initialize(options) ⇒ BumpString
constructor
A new instance of BumpString.
- #key_part ⇒ Object
- #matched ⇒ Object
- #pattern ⇒ Object
- #pattern_replace ⇒ Object
- #update_version(matched_version) ⇒ Object
Constructor Details
#initialize(options) ⇒ BumpString
Returns a new instance of BumpString.
3 4 5 |
# File 'lib/bumpversion/bump_string.rb', line 3 def initialize() @options = end |
Instance Method Details
#bump ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# 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 ⇒ Object
7 8 9 |
# File 'lib/bumpversion/bump_string.rb', line 7 def dictionary %w[major minor patch build].map { |k| k.to_sym } end |
#key_part ⇒ Object
11 12 13 |
# File 'lib/bumpversion/bump_string.rb', line 11 def key_part @options[:part].to_sym end |
#matched ⇒ Object
23 24 25 |
# File 'lib/bumpversion/bump_string.rb', line 23 def matched @match ||= pattern.match(@options[:current_version]) end |
#pattern ⇒ Object
15 16 17 |
# File 'lib/bumpversion/bump_string.rb', line 15 def pattern /(?<major>\d+).(?<minor>\d+).(?<patch>\d+).?(?<build>\d+)?/ end |
#pattern_replace ⇒ Object
19 20 21 |
# 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) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# 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 |