Class: Gitlab::CycleAnalytics::Updater

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/cycle_analytics/updater.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_result, from:, to:, klass:) ⇒ Updater

Returns a new instance of Updater.


10
11
12
13
14
15
# File 'lib/gitlab/cycle_analytics/updater.rb', line 10

def initialize(event_result, from:, to:, klass:)
  @event_result = event_result
  @klass = klass
  @from = from
  @to = to
end

Class Method Details

.update!(*args) ⇒ Object


6
7
8
# File 'lib/gitlab/cycle_analytics/updater.rb', line 6

def self.update!(*args)
  new(*args).update!
end

Instance Method Details

#itemsObject


27
28
29
# File 'lib/gitlab/cycle_analytics/updater.rb', line 27

def items
  @items ||= @klass.find(result_ids).group_by { |item| item['id'] }
end

#result_idsObject


23
24
25
# File 'lib/gitlab/cycle_analytics/updater.rb', line 23

def result_ids
  @event_result.map { |event| event[@from] }
end

#update!Object


17
18
19
20
21
# File 'lib/gitlab/cycle_analytics/updater.rb', line 17

def update!
  @event_result.each do |event|
    event[@to] = items[event.delete(@from).to_i].first
  end
end