class Anvil::Versioner

Constants

TERMS

Attributes

version[R]

Public Class Methods

new(string) click to toggle source
Calls superclass method
# File lib/anvil/versioner.rb, line 15
def initialize(string)
  version = Semantic::Version.new(string)
  super(version)
end

Public Instance Methods

bump!(term) click to toggle source

Bumps a version by incrementing one of its terms and reseting the others according to semver specification.

@example

Versioner.new('1.2.3-alpha.1+build.2').bump(:major)
  # => '2.0.0'
Versioner.new('1.2.3-alpha.1+build.2').bump(:minor)
  # => '1.3.0'
Versioner.new('1.2.3-alpha.1+build.2').bump(:patch)
  # => '1.2.4'
Versioner.new('1.2.3-alpha.1+build.2').bump(:pre)
  # => '1.2.3-alpha.2'
Versioner.new('1.2.3-alpha.1+build.2').bump(:build)
  # => '1.2.3-alpha.2+build.3'

@param term [Symbol] the term to increment @raise [Anvil::Versioner::NotSuportedTerm] When the given term is invalid

# File lib/anvil/versioner.rb, line 41
def bump!(term)
  fail NotSupportedTerm.new(term) unless TERMS.include?(term.to_sym)

  new_version = clone
  new_value = increment send(term)

  new_version.send("#{term}=", new_value)
  new_version.reset_terms_for(term)
end

Protected Instance Methods

increment(old_value) click to toggle source
# File lib/anvil/versioner.rb, line 53
def increment(old_value)
  case old_value
  when Fixnum
    old_value + 1
  when String
    components = old_value.split('.')
    components[-1] = components[-1].to_i + 1
    components.join('.')
  end
end
reset_terms_for(term) click to toggle source

Resets all the terms which need to be reset after a bump

@param term [Symbol] The term which has been bumped @return [Anvil::Versioner] A new version with the proper number @todo we still need to reset pre-release and builds properly

# File lib/anvil/versioner.rb, line 69
def reset_terms_for(term)
  self.minor = 0 if term == :major
  self.patch = 0 if term == :major || term == :minor
  self.pre   = nil if [:major, :minor, :patch].include? term
  self.build = nil if [:major, :minor, :patch, :pre].include? term

  self
end