Method: Tap::Support::Versions#increment
- Defined in:
- lib/tap/support/versions.rb
#increment(path, increment) ⇒ Object
Increments the version of the filepath by the specified increment.
increment("path/to/file-1.0.txt", "0.0.1") # => "path/to/file-1.0.1.txt"
increment("path/to/file.txt", 1.0) # => "path/to/file-1.0.txt"
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tap/support/versions.rb', line 31 def increment(path, increment) path, version = deversion(path) # split the version and increment into integer arrays of equal length increment, version = [increment, version].collect do |vstr| begin vstr.to_s.split(/\./).collect {|v| v.to_i} rescue raise "Bad version or increment: #{vstr}" end end version.concat Array.new(increment.length - version.length, 0) if increment.length > version.length # add the increment to version 0.upto(version.length-1) do |i| version[i] += (increment[i] || 0) end self.version(path, version.join(".")) end |