gitlab-org--gitlab-foss/lib/gitlab/cycle_analytics/updater.rb

31 lines
629 B
Ruby
Raw Normal View History

module Gitlab
module CycleAnalytics
class Updater
def self.update!(*args)
new(*args).update!
end
2016-11-18 07:00:38 -05:00
def initialize(event_result, from:, to:, klass:)
@event_result = event_result
2016-11-18 07:00:38 -05:00
@klass = klass
@from = from
@to = to
end
def update!
@event_result.each do |event|
2016-11-18 07:00:38 -05:00
event[@to] = items[event.delete(@from).to_i].first
end
end
def result_ids
2016-11-18 07:00:38 -05:00
@event_result.map { |event| event[@from] }
end
def items
2016-11-18 07:00:38 -05:00
@items ||= @klass.find(result_ids).group_by { |item| item['id'] }
end
end
end
end