diff options
author | Thong Kuah <tkuah@gitlab.com> | 2018-10-30 13:33:43 +0300 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2018-11-01 09:37:32 +0300 |
commit | 1163b235391668d53ae0cea80bc22d40b365e0a7 (patch) | |
tree | ce2cf692f41fba52eb42e767611e130399c85499 /app/presenters/clusterable_presenter.rb | |
parent | 88800abcd8741b07114c2850e00b74fbecfbf90e (diff) |
Move view and path concerns to presenters
- Move show path for cluster to ClusterPresenter
- Create ClusterablePresenter to encapsulate logic. Consolidates
scattered methods from BaseController and ClustersHelper into an object.
Diffstat (limited to 'app/presenters/clusterable_presenter.rb')
-rw-r--r-- | app/presenters/clusterable_presenter.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/presenters/clusterable_presenter.rb b/app/presenters/clusterable_presenter.rb new file mode 100644 index 00000000000..c857d57b003 --- /dev/null +++ b/app/presenters/clusterable_presenter.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class ClusterablePresenter < Gitlab::View::Presenter::Delegated + presents :clusterable + + def self.fabricate(clusterable, **attributes) + presenter_class = "#{clusterable.class.name}ClusterablePresenter".constantize + attributes_with_presenter_class = attributes.merge(presenter_class: presenter_class) + + Gitlab::View::Presenter::Factory + .new(clusterable, attributes_with_presenter_class) + .fabricate! + end + + def can_create_cluster? + can?(current_user, :create_cluster, clusterable) + end + + def index_path + raise NotImplementedError + end + + def new_path + raise NotImplementedError + end + + def clusterable_params + raise NotImplementedError + end +end |