Class: AppVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/app-version-git.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ AppVersion

Returns a new instance of AppVersion.



7
8
9
# File 'lib/app-version-git.rb', line 7

def initialize path
  @git = Git.open(get_path path)
end

Instance Method Details

#changelog(count = 40) ⇒ Object



32
33
34
35
36
# File 'lib/app-version-git.rb', line 32

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) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/app-version-git.rb', line 11

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

#versionObject



24
25
26
27
28
29
30
# File 'lib/app-version-git.rb', line 24

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