Module: Gitlab::View::Presenter::Base

Extended by:
ActiveSupport::Concern
Includes:
Allowable, Routing
Included in:
Delegated, Simple
Defined in:
lib/gitlab/view/presenter/base.rb

Instance Method Summary collapse

Methods included from Routing

includes_helpers, redirect_legacy_paths, url_helpers

Instance Method Details

#__subject__Object

Presenters should always access the subject through an explicit getter defined with ‘presents …, as:`, the `__subject__` method is only intended for internal use.



16
17
18
# File 'lib/gitlab/view/presenter/base.rb', line 16

def __subject__
  @subject
end

#can?(user, action, overridden_subject = nil) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/gitlab/view/presenter/base.rb', line 20

def can?(user, action, overridden_subject = nil)
  super(user, action, overridden_subject || __subject__)
end

#declarative_policy_delegateObject

delegate all #can? queries to the subject



25
26
27
# File 'lib/gitlab/view/presenter/base.rb', line 25

def declarative_policy_delegate
  __subject__
end

#is_a?(type) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/gitlab/view/presenter/base.rb', line 37

def is_a?(type)
  super || __subject__.is_a?(type)
end

#path_with_line_numbers(path, start_line, end_line) ⇒ Object



49
50
51
52
53
54
# File 'lib/gitlab/view/presenter/base.rb', line 49

def path_with_line_numbers(path, start_line, end_line)
  path.tap do |complete_path|
    complete_path << "#L#{start_line}"
    complete_path << "-#{end_line}" if end_line && end_line != start_line
  end
end

#present(**attributes) ⇒ Object



29
30
31
# File 'lib/gitlab/view/presenter/base.rb', line 29

def present(**attributes)
  self
end

#url_builderObject



33
34
35
# File 'lib/gitlab/view/presenter/base.rb', line 33

def url_builder
  Gitlab::UrlBuilder.instance
end

#web_pathObject



45
46
47
# File 'lib/gitlab/view/presenter/base.rb', line 45

def web_path
  url_builder.build(__subject__, only_path: true)
end

#web_urlObject



41
42
43
# File 'lib/gitlab/view/presenter/base.rb', line 41

def web_url
  url_builder.build(__subject__)
end