Class: GritWrapper
Instance Method Summary collapse
- #[](key) ⇒ Object
- #head ⇒ Object
- #last_commit ⇒ Object
- #last_commit_hash ⇒ Object
- #repository ⇒ Object
- #repository? ⇒ Boolean
- #to_hash ⇒ Object
Instance Method Details
#[](key) ⇒ Object
49 50 51 |
# File 'lib/grit_wrapper.rb', line 49 def [](key) to_hash[key] end |
#head ⇒ Object
22 23 24 |
# File 'lib/grit_wrapper.rb', line 22 def head @head ||= repository.head end |
#last_commit ⇒ Object
30 31 32 |
# File 'lib/grit_wrapper.rb', line 30 def last_commit @last_commit ||= repository.commit(last_commit_hash) || OpenStruct.new end |
#last_commit_hash ⇒ Object
26 27 28 |
# File 'lib/grit_wrapper.rb', line 26 def last_commit_hash @last_commit_hash ||= head.commit.to_s end |
#repository ⇒ Object
11 12 13 14 15 16 |
# File 'lib/grit_wrapper.rb', line 11 def repository @repository ||= Grit::Repo.new('.') rescue Grit::InvalidGitRepositoryError # not in a directory that contains .git @repository = :invalid end |
#repository? ⇒ Boolean
18 19 20 |
# File 'lib/grit_wrapper.rb', line 18 def repository? !repository.nil? && repository != :invalid end |
#to_hash ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/grit_wrapper.rb', line 34 def to_hash return { :branch => 'Not currently on a branch.', :commit => (File.read("REVISION").strip rescue nil) } if head.nil? @hash ||= { :branch => head.name, :commit => last_commit_hash, :last_author => last_commit., :message => last_commit., :date => last_commit. } end |