Class: GitWakaTime::Query

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

Overview

Integrates the nested hash from mapper with heartbeats api

Instance Method Summary collapse

Constructor Details

#initialize(start_at, end_at, project) ⇒ Query

Returns a new instance of Query.



7
8
9
10
11
12
13
# File 'lib/gitwakatime/query.rb', line 7

def initialize(start_at, end_at, project)
  @start_at = start_at
  @end_at = end_at
  @project = project
  @requests = RequestBuilder.new(@start_at, @end_at).call
  Log.new "Loading Committed time from #{@start_at} to #{@end_at}".red
end

Instance Method Details

#cached?(date) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'lib/gitwakatime/query.rb', line 25

def cached?(date)
  max_local_timestamp = Heartbeat.max(:time)
  return false if max_local_timestamp.nil?
  @max_local_timestamp ||= (Time.parse(max_local_timestamp + ' UTC'))
  date.to_date < @max_local_timestamp.to_date
end

#callObject



15
16
17
18
19
20
21
22
23
# File 'lib/gitwakatime/query.rb', line 15

def call
  @requests.each do |params|
    next if cached?(params[:date])
    persist_heartbeats_localy(Request.new(params).call)
  end

  DurationsCalculator.new(heartbeats: local_heartbeats.where('duration <= 0') ).heartbeats_to_durations
  local_heartbeats.where(project: @project).all
end