diff options
Diffstat (limited to 'lib/gitlab/view/presenter/base.rb')
-rw-r--r-- | lib/gitlab/view/presenter/base.rb | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/gitlab/view/presenter/base.rb b/lib/gitlab/view/presenter/base.rb index 3bacad72050..a2d217fb42f 100644 --- a/lib/gitlab/view/presenter/base.rb +++ b/lib/gitlab/view/presenter/base.rb @@ -11,15 +11,19 @@ module Gitlab include Gitlab::Routing include Gitlab::Allowable - attr_reader :subject + # Presenters should always access the subject through an explicit getter defined with + # `presents ..., as:`, the `__subject__` method is only intended for internal use. + def __subject__ + @subject + end def can?(user, action, overridden_subject = nil) - super(user, action, overridden_subject || subject) + super(user, action, overridden_subject || __subject__) end # delegate all #can? queries to the subject def declarative_policy_delegate - subject + __subject__ end def present(**attributes) @@ -31,15 +35,15 @@ module Gitlab end def is_a?(type) - super || subject.is_a?(type) + super || __subject__.is_a?(type) end def web_url - url_builder.build(subject) + url_builder.build(__subject__) end def web_path - url_builder.build(subject, only_path: true) + url_builder.build(__subject__, only_path: true) end class_methods do @@ -58,7 +62,7 @@ module Gitlab # no-op end - define_method(as) { subject } if as + define_method(as) { __subject__ } if as end end end |