class VersionIncrementer

Implements version incrementation support.

Public Class Methods

new(filename=nil) click to toggle source

If optional filename is supplied, load the version from the file.

# File lib/rakeutils/versioninc.rb, line 17
def initialize(filename=nil)
  @version = [0,0,0]
  read(filename) unless filename.nil?
end

Public Instance Methods

inc_build( filename ) click to toggle source
# File lib/rakeutils/versioninc.rb, line 38
def inc_build( filename )
  read( filename )
  @version[2] = @version[2] + 1
  write( filename )
end
inc_major( filename ) click to toggle source
# File lib/rakeutils/versioninc.rb, line 26
def inc_major( filename )
  read( filename )
  @version[0] = @version[0] + 1
  write( filename )
end
inc_minor( filename ) click to toggle source
# File lib/rakeutils/versioninc.rb, line 32
def inc_minor( filename )
  read( filename )
  @version[1] = @version[1] + 1
  write( filename )
end
version() click to toggle source
# File lib/rakeutils/versioninc.rb, line 22
def version()
  @version.join(".")
end
write_setup_ini(filename) click to toggle source
# File lib/rakeutils/versioninc.rb, line 44
def write_setup_ini(filename)
  version = @version.join(".")
  open(filename, 'w') do |f|
    f << "[Info]\n"
    f << "VerInfo=#{version}\n"
  end
end

Private Instance Methods

read(filename) click to toggle source
# File lib/rakeutils/versioninc.rb, line 59
def read(filename)
  filepath = filename

  version = ""
  open(filepath) { |f| version = f.gets(nil) }
  version.strip!
  version.chomp!

  a_version = version.split( "." )
  if( a_version.length != 3 )
    puts "ERROR: Version string must be 3 components. Bad string: #{version}"
    return
  end

  a_version.each_index do |i|
    @version[i] = a_version[i].to_i
  end
end
write(filename) click to toggle source
# File lib/rakeutils/versioninc.rb, line 54
def write(filename)
  version = @version.join(".")
  open(filename, 'w') { |f| f << version }
end