class AppVersion

Public Class Methods

new(path) click to toggle source
# File lib/app-version-git.rb, line 6
def initialize path
  @git = Git.open(get_path path)
end

Public Instance Methods

changelog(count = 40) click to toggle source
# File lib/app-version-git.rb, line 31
def changelog count = 40
  @git.log(count).collect{|l|
      { :sha => l.sha, :date => l.date, :author => l.committer.name, :message => l.message  }
    }
end
get_path(path) click to toggle source
# File lib/app-version-git.rb, line 10
def get_path path
  path = File.expand_path(File.dirname(path))
  path = path.split("/")
  while path.size > 0
    if File.exists?(File.join(path, ".git"))
      return File.join(path)
    else
      path = path[0..-2]
    end
  end
  raise ArgumentError, "Git repository couldn't be found in your path"
end
version() click to toggle source
# File lib/app-version-git.rb, line 23
def version
  log_count = @git.log(99999).size
  patch = log_count % 10
  minor = log_count/10 % 10
  major = log_count/100 % 10
  "#{major}.#{minor}.#{patch}"
end