Use switch case in a helper, feedback:

https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5142#note_13988401
This commit is contained in:
Lin Jen-Shin 2016-08-17 17:38:38 +08:00
parent ee33b3e6e8
commit 4fbe044b74
2 changed files with 18 additions and 7 deletions

View File

@ -35,14 +35,10 @@ class Projects::ArtifactsController < Projects::ApplicationController
end
def latest_succeeded
path = params[:path]
target_url = artifacts_action_url(params[:path], project, build)
if %w[download browse file].include?(path)
redirect_to send(
"#{path}_namespace_project_build_artifacts_url",
project.namespace,
project,
build)
if target_url
redirect_to(target_url)
else
render_404
end

View File

@ -149,4 +149,19 @@ module GitlabRoutingHelper
def resend_invite_group_member_path(group_member, *args)
resend_invite_group_group_member_path(group_member.source, group_member)
end
# Artifacts
def artifacts_action_url(path, project, build)
args = [project.namespace, project, build]
case path
when 'download'
download_namespace_project_build_artifacts_url(*args)
when 'browse'
browse_namespace_project_build_artifacts_url(*args)
when 'file'
file_namespace_project_build_artifacts_url(*args)
end
end
end