gitlab-org--gitlab-foss/lib/gitlab/cycle_analytics/updater.rb
gfyoung 7e6f6e1603 Enable even more frozen string in lib/gitlab
Enables frozens string for the following:

* lib/gitlab/conflict/**/*.rb
* lib/gitlab/cross_project_access/**/*.rb
* lib/gitlab/cycle_analytics/**/*.rb
* lib/gitlab/data_builder/**/*.rb
* lib/gitlab/database/**/*.rb
* lib/gitlab/dependency_linker/**/*.rb
* lib/gitlab/diff/**/*.rb
* lib/gitlab/downtime_check/**/*.rb
* lib/gitlab/email/**/*.rb
* lib/gitlab/etag_caching/**/*.rb

Partially addresses gitlab-org/gitlab-ce#47424.
2018-11-06 22:47:32 -08:00

32 lines
660 B
Ruby

# frozen_string_literal: true
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