class Crackin::VersionFile

Public Class Methods

new(path) click to toggle source
# File lib/crackin/version_file.rb, line 3
def initialize(path)
  @path = path
  load
end

Public Instance Methods

alpha() click to toggle source
# File lib/crackin/version_file.rb, line 81
def alpha
  tag('alpha')
  name
end
beta() click to toggle source
# File lib/crackin/version_file.rb, line 76
def beta
  tag('beta')
  name
end
load() click to toggle source
# File lib/crackin/version_file.rb, line 8
def load
  File.read(@path).lines.each do |line|
    @major = $1.to_i if line =~ /MAJOR\s+=\s+(\d+)/
    @minor = $1.to_i if line =~ /MINOR\s+=\s+(\d+)/
    @tiny = $1.to_i if line =~ /TINY\s+=\s+(\d+)/
    if line =~ /TAG\s+=\s+(.*)/
      @tag = $1
      @tag.gsub!(/['"]/, '')
      @tag = nil if @tag == 'nil'
    end
  end
end
major() click to toggle source
# File lib/crackin/version_file.rb, line 50
def major
  @major += 1
  @minor = 0
  @tiny = 0
  @tag = nil
  name
end
minor() click to toggle source
# File lib/crackin/version_file.rb, line 58
def minor
  @minor += 1
  @tiny = 0
  @tag = nil
  name
end
name() click to toggle source
# File lib/crackin/version_file.rb, line 34
def name
  "v#{number}"
end
none() click to toggle source
# File lib/crackin/version_file.rb, line 96
def none

end
number() click to toggle source
# File lib/crackin/version_file.rb, line 46
def number
  to_a.join('.')
end
rc() click to toggle source
# File lib/crackin/version_file.rb, line 71
def rc
  tag('rc')
  name
end
save() click to toggle source
# File lib/crackin/version_file.rb, line 21
def save
  out = []
  tag = @tag ? "'#{@tag}'" : "nil"
  File.open(@path).lines.each do |line|; line.chomp!
    line.gsub!(/(\s+)MAJOR\s+=\s+\d+/, "\\1MAJOR = #{@major}")
    line.gsub!(/(\s+)MINOR\s+=\s+\d+/, "\\1MINOR = #{@minor}")
    line.gsub!(/(\s+)TINY\s+=\s+\d+/, "\\1TINY = #{@tiny}")
    line.gsub!(/(\s+)TAG\s+=\s+(nil|['"].*['"])/, "\\1TAG = #{tag}")
    out << line
  end
  File.open(@path, "w+") {|f| f.write(out.join("\n"))}
end
tag(type) click to toggle source
# File lib/crackin/version_file.rb, line 86
def tag(type)
  if @tag =~ /#{type}(\d+)/
    num = $1.to_i + 1
    @tag = "#{type}#{num}"
  else
    @tiny += 1
    @tag = "#{type}0"
  end
end
tiny() click to toggle source
# File lib/crackin/version_file.rb, line 65
def tiny
  @tiny += 1 unless @tag
  @tag = nil
  name
end
to_a() click to toggle source
# File lib/crackin/version_file.rb, line 42
def to_a
  [@major, @minor, @tiny, @tag].compact
end
to_s() click to toggle source
# File lib/crackin/version_file.rb, line 38
def to_s
  name
end