Class: DocHealth::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/doc_health/git.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Git

Returns a new instance of Git.



9
10
11
12
# File 'lib/doc_health/git.rb', line 9

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

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/doc_health/git.rb', line 7

def path
  @path
end

Instance Method Details

#file_commit_authorObject



14
15
16
17
18
19
20
# File 'lib/doc_health/git.rb', line 14

def file_commit_author
  Dir.glob("#{path}**/*.md").map do |file|
    est_time = last_commit_date(file)
    author = last_commit_author(file)
    [file, est_time, author]
  end
end

#last_commit_author(file) ⇒ Object



30
31
32
33
34
35
# File 'lib/doc_health/git.rb', line 30

def last_commit_author(file)
  gitlog = @git.log(1).object(file).first
  return "N/A" unless gitlog

  @git.log(1).object(file).first.author.name
end

#last_commit_date(file) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/doc_health/git.rb', line 22

def last_commit_date(file)
  # handle new files not in the git history
  gitlog = @git.log(1).object(file).first
  return "N/A" unless gitlog

  gitlog.date.getlocal("-05:00").strftime("%Y-%m-%d %I:%M %p")
end