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
|
|
|
|
include Gitlab::View::Presenter::Base
|
|
|
|
|
|
|
|
def initialize(subject, **attributes)
|
|
|
|
@subject = subject
|
|
|
|
|
|
|
|
attributes.each do |key, value|
|
2017-01-24 11:07:56 -05:00
|
|
|
if subject.respond_to?(key)
|
|
|
|
raise CannotOverrideMethodError.new("#{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
|