Class: Workarea::Admin::Reports::TimelineViewModel::Event

Inherits:
Object
  • Object
show all
Defined in:
app/view_models/workarea/admin/reports/timeline_view_model.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, type:, occurred_at:) ⇒ Event

Returns a new instance of Event.



33
34
35
36
37
# File 'app/view_models/workarea/admin/reports/timeline_view_model.rb', line 33

def initialize(model, type:, occurred_at:)
  @model = model
  @type = type
  @occurred_at = occurred_at
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



31
32
33
# File 'app/view_models/workarea/admin/reports/timeline_view_model.rb', line 31

def model
  @model
end

#occurred_atObject (readonly)

Returns the value of attribute occurred_at.



31
32
33
# File 'app/view_models/workarea/admin/reports/timeline_view_model.rb', line 31

def occurred_at
  @occurred_at
end

#typeObject (readonly)

Returns the value of attribute type.



31
32
33
# File 'app/view_models/workarea/admin/reports/timeline_view_model.rb', line 31

def type
  @type
end

Class Method Details

.build(releases, custom_events) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/view_models/workarea/admin/reports/timeline_view_model.rb', line 8

def self.build(releases, custom_events)
  result = Hash.new { |h, k| h[k] = [] }

  releases.each do |release|
    result[release.published_at.to_date] << new(
      Workarea::Admin::ReleaseViewModel.wrap(release),
      type: 'release',
      occurred_at: release.published_at
    )
  end

  custom_events.each do |event|
    result[event.occurred_at.to_date] << new(
      event,
      type: 'custom_event',
      occurred_at: event.occurred_at
    )
  end

  result.sort.to_h
end