Class: GitWakaTime::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/gitwakatime/mapper.rb

Overview

Th

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(commits: 500, start_at: Date.today) ⇒ Mapper

Returns a new instance of Mapper.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gitwakatime/mapper.rb', line 5

def initialize(commits: 500, start_at: Date.today)
  Log.new 'Mapping commits for dependent commits'
  time = Benchmark.realtime do
    g = GitWakaTime.config.git
    project = File.basename(g.dir.path)
    logs =  g.log(commits).since(start_at).until(Date.today)

    @commits = logs.map do |git_c|
      next if git_c.author.name != GitWakaTime.config.user_name
      next if git_c.parents.size > 1

      Commit.find_or_create(
        sha: git_c.sha,
        project: project
      ) do |c|
        c.update(
          author: git_c.author.name,
          message: git_c.message,
          date: git_c.date.utc
        )
      end
    end.compact
  end
  Log.new "Map Completed took #{time}s with #{@commits.size} commits"
end

Instance Attribute Details

#commitsObject

Returns the value of attribute commits.



4
5
6
# File 'lib/gitwakatime/mapper.rb', line 4

def commits
  @commits
end

#gitObject

Returns the value of attribute git.



4
5
6
# File 'lib/gitwakatime/mapper.rb', line 4

def git
  @git
end