Class: GitWrapper
Instance Method Summary collapse
- #[](key) ⇒ Object
- #last_commit ⇒ Object
- #last_commit_hash ⇒ Object
- #repository ⇒ Object
- #repository? ⇒ Boolean
- #to_hash ⇒ Object
Instance Method Details
#[](key) ⇒ Object
50 51 52 |
# File 'lib/git_wrapper.rb', line 50 def [](key) to_hash[key] end |
#last_commit ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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 ⇒ Object
17 18 19 |
# File 'lib/git_wrapper.rb', line 17 def last_commit_hash @last_commit_hash ||= `git rev-parse HEAD`.strip end |
#repository ⇒ Object
9 10 11 |
# File 'lib/git_wrapper.rb', line 9 def repository @repository = (Dir.new('./.git') rescue :invalid) end |
#repository? ⇒ Boolean
13 14 15 |
# File 'lib/git_wrapper.rb', line 13 def repository? !repository.nil? && repository != :invalid end |
#to_hash ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# 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., :message => last_commit., :date => last_commit. } end |