debian-mirror-gitlab/lib/gitlab/cycle_analytics/updater.rb

33 lines
660 B
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
module CycleAnalytics
class Updater
def self.update!(*args)
new(*args).update!
end
def initialize(event_result, from:, to:, klass:)
@event_result = event_result
@klass = klass
@from = from
@to = to
end
def update!
@event_result.each do |event|
event[@to] = items[event.delete(@from).to_i].first
end
end
def result_ids
@event_result.map { |event| event[@from] }
end
def items
@items ||= @klass.find(result_ids).group_by { |item| item['id'] }
end
end
end
end