class GitWrapper
Public Instance Methods
[](key)
click to toggle source
# File lib/git_wrapper.rb, line 50 def [](key) to_hash[key] end
last_commit()
click to toggle source
# File lib/git_wrapper.rb, line 21 def last_commit @last_commit ||= begin if repository? OpenStruct.new( author: `git show -s --format='format:%an <%ae>'`.strip, message: `git show -s --format='%s'`.strip, authored_date: Time.at(`git show -s --format='format:%at'`.to_i) ) else OpenStruct.new() end end end
last_commit_hash()
click to toggle source
# File lib/git_wrapper.rb, line 17 def last_commit_hash @last_commit_hash ||= `git rev-parse HEAD`.strip end
repository()
click to toggle source
# File lib/git_wrapper.rb, line 9 def repository @repository = (Dir.new('./.git') rescue :invalid) end
repository?()
click to toggle source
# File lib/git_wrapper.rb, line 13 def repository? !repository.nil? && repository != :invalid end
to_hash()
click to toggle source
# File lib/git_wrapper.rb, line 35 def to_hash return { :branch => 'Not currently on a branch.', :commit => (File.read("REVISION").strip rescue nil) } unless repository? @hash ||= { :branch => `git rev-parse --abbrev-ref HEAD`.strip, :commit => last_commit_hash, :last_author => last_commit.author, :message => last_commit.message, :date => last_commit.authored_date } end