Class: Gitlab::CycleAnalytics::Updater
- Inherits:
-
Object
- Object
- Gitlab::CycleAnalytics::Updater
- Defined in:
- lib/gitlab/cycle_analytics/updater.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(event_result, from:, to:, klass:) ⇒ Updater
constructor
A new instance of Updater.
- #items ⇒ Object
- #result_ids ⇒ Object
- #update! ⇒ Object
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! ⇒ Object
6 7 8 |
# File 'lib/gitlab/cycle_analytics/updater.rb', line 6 def self.update!(...) new(...).update! end |
Instance Method Details
#items ⇒ Object
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_ids ⇒ Object
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 |