Class: EventPresenter

Inherits:
Gitlab::View::Presenter::Delegated show all
Defined in:
app/presenters/event_presenter.rb

Instance Attribute Summary

Attributes included from Gitlab::View::Presenter::Base

#subject

Instance Method Summary collapse

Methods included from Gitlab::View::Presenter::Base

#can?, #declarative_policy_delegate, #is_a?, #present, #url_builder, #web_path, #web_url

Methods included from Gitlab::Allowable

#can?

Methods included from Gitlab::Routing

add_helpers, includes_helpers, redirect_legacy_paths, url_helpers

Constructor Details

#initialize(subject, **attributes) ⇒ EventPresenter

Returns a new instance of EventPresenter.


6
7
8
9
10
# File 'app/presenters/event_presenter.rb', line 6

def initialize(subject, **attributes)
  super

  @visible_to_user_cache = ActiveSupport::Cache::MemoryStore.new
end

Instance Method Details

#resource_parent_nameObject

implement cache here


18
19
20
# File 'app/presenters/event_presenter.rb', line 18

def resource_parent_name
  resource_parent&.full_name || ''
end

22
23
24
25
26
27
28
29
30
31
# File 'app/presenters/event_presenter.rb', line 22

def target_link_options
  case resource_parent
  when Group
    [event.group, event.target]
  when Project
    [event.project, event.target]
  else
    ''
  end
end

#visible_to_user?(user = nil) ⇒ Boolean

Caching `visible_to_user?` method in the presenter beause it might be called multiple times.

Returns:

  • (Boolean)

13
14
15
# File 'app/presenters/event_presenter.rb', line 13

def visible_to_user?(user = nil)
  @visible_to_user_cache.fetch(user&.id) { super(user) }
end