Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-07-28 15:35:02 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-07-28 15:35:02 +0300
commit9ae1ecf876e40ce9dd64c72e025f32e38c882fd6 (patch)
tree8803b574cf48b2c8bc38e6fce295065d737bc730 /lib/gitlab/badge
parent42c035ee38a6629090da07aea818f4c9e3733075 (diff)
Extract build status badge metadata to separate class
Diffstat (limited to 'lib/gitlab/badge')
-rw-r--r--lib/gitlab/badge/build.rb25
-rw-r--r--lib/gitlab/badge/build/metadata.rb36
2 files changed, 40 insertions, 21 deletions
diff --git a/lib/gitlab/badge/build.rb b/lib/gitlab/badge/build.rb
index e5e9fab3f5c..21d60854bf5 100644
--- a/lib/gitlab/badge/build.rb
+++ b/lib/gitlab/badge/build.rb
@@ -4,15 +4,15 @@ module Gitlab
# Build badge
#
class Build
- include Gitlab::Application.routes.url_helpers
- include ActionView::Helpers::AssetTagHelper
- include ActionView::Helpers::UrlHelper
-
def initialize(project, ref)
@project, @ref = project, ref
@image = ::Ci::ImageForBuildService.new.execute(project, ref: ref)
end
+ def metadata
+ Build::Metadata.new(@project, @ref)
+ end
+
def type
'image/svg+xml'
end
@@ -24,23 +24,6 @@ module Gitlab
def to_s
@image[:name].sub(/\.svg$/, '')
end
-
- def to_html
- link_to(image_tag(image_url, alt: 'build status'), link_url)
- end
-
- def to_markdown
- "[![build status](#{image_url})](#{link_url})"
- end
-
- def image_url
- build_namespace_project_badges_url(@project.namespace,
- @project, @ref, format: :svg)
- end
-
- def link_url
- namespace_project_commits_url(@project.namespace, @project, id: @ref)
- end
end
end
end
diff --git a/lib/gitlab/badge/build/metadata.rb b/lib/gitlab/badge/build/metadata.rb
new file mode 100644
index 00000000000..553ef8d7b16
--- /dev/null
+++ b/lib/gitlab/badge/build/metadata.rb
@@ -0,0 +1,36 @@
+module Gitlab
+ module Badge
+ class Build
+ ##
+ # Class that describes build badge metadata
+ #
+ class Metadata
+ include Gitlab::Application.routes.url_helpers
+ include ActionView::Helpers::AssetTagHelper
+ include ActionView::Helpers::UrlHelper
+
+ def initialize(project, ref)
+ @project = project
+ @ref = ref
+ end
+
+ def to_html
+ link_to(image_tag(image_url, alt: 'build status'), link_url)
+ end
+
+ def to_markdown
+ "[![build status](#{image_url})](#{link_url})"
+ end
+
+ def image_url
+ build_namespace_project_badges_url(@project.namespace,
+ @project, @ref, format: :svg)
+ end
+
+ def link_url
+ namespace_project_commits_url(@project.namespace, @project, id: @ref)
+ end
+ end
+ end
+ end
+end