2018-11-19 21:01:13 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-09 15:45:49 -05:00
|
|
|
module Gitlab
|
|
|
|
module View
|
|
|
|
module Presenter
|
|
|
|
class Delegated < SimpleDelegator
|
2021-09-21 05:12:21 -04:00
|
|
|
extend ::Gitlab::Utils::DelegatorOverride
|
|
|
|
|
|
|
|
# TODO: Stop including auxiliary methods/modules in `Presenter::Base` as
|
|
|
|
# it overrides many methods in the Active Record models.
|
|
|
|
# See https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/presenters/README.md#validate-accidental-overrides
|
|
|
|
# for more information.
|
2017-01-09 15:45:49 -05:00
|
|
|
include Gitlab::View::Presenter::Base
|
2021-09-21 05:12:21 -04:00
|
|
|
delegator_override_with Gitlab::Routing.url_helpers
|
|
|
|
delegator_override :can?
|
|
|
|
delegator_override :declarative_policy_delegate
|
|
|
|
delegator_override :present
|
|
|
|
delegator_override :web_url
|
2017-01-09 15:45:49 -05:00
|
|
|
|
|
|
|
def initialize(subject, **attributes)
|
|
|
|
@subject = subject
|
|
|
|
|
|
|
|
attributes.each do |key, value|
|
2017-01-24 11:07:56 -05:00
|
|
|
if subject.respond_to?(key)
|
2021-05-04 11:10:36 -04:00
|
|
|
raise CannotOverrideMethodError, "#{subject} already respond to #{key}!"
|
2017-01-20 12:13:14 -05:00
|
|
|
end
|
2017-01-24 11:07:56 -05:00
|
|
|
|
|
|
|
define_singleton_method(key) { value }
|
2017-01-09 15:45:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
super(subject)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|