Class: GritWrapper

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/grit_wrapper.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



49
50
51
# File 'lib/grit_wrapper.rb', line 49

def [](key)
  to_hash[key]
end

#headObject



22
23
24
# File 'lib/grit_wrapper.rb', line 22

def head
  @head ||= repository.head
end

#last_commitObject



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_hashObject



26
27
28
# File 'lib/grit_wrapper.rb', line 26

def last_commit_hash
  @last_commit_hash ||= head.commit.to_s
end

#repositoryObject



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

Returns:

  • (Boolean)


18
19
20
# File 'lib/grit_wrapper.rb', line 18

def repository?
  !repository.nil? && repository != :invalid
end

#to_hashObject



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.author,
    :message => last_commit.message,
    :date => last_commit.authored_date
  }
end