Class: Gitlab::Badge::Pipeline::Template

Inherits:
Template
  • Object
show all
Defined in:
lib/gitlab/badge/pipeline/template.rb

Overview

Class that represents a pipeline badge template.

Template object will be passed to badge.svg.erb template.

Constant Summary collapse

STATUS_RENAME =
{ 'success' => 'passed' }.freeze
STATUS_COLOR =
{
  success: '#4c1',
  failed: '#e05d44',
  running: '#dfb317',
  pending: '#dfb317',
  preparing: '#a7a7a7',
  canceled: '#9f9f9f',
  skipped: '#9f9f9f',
  unknown: '#9f9f9f'
}.freeze

Constants inherited from Template

Template::MAX_KEY_TEXT_SIZE, Template::MAX_KEY_WIDTH

Instance Method Summary collapse

Methods inherited from Template

#key_color, #key_text_anchor, #value_text_anchor, #width

Constructor Details

#initialize(badge) ⇒ Template

Returns a new instance of Template.


24
25
26
27
28
29
# File 'lib/gitlab/badge/pipeline/template.rb', line 24

def initialize(badge)
  @entity = badge.entity
  @status = badge.status
  @key_text = badge.customization.dig(:key_text)
  @key_width = badge.customization.dig(:key_width)
end

Instance Method Details

#key_textObject


31
32
33
34
35
36
37
# File 'lib/gitlab/badge/pipeline/template.rb', line 31

def key_text
  if @key_text && @key_text.size <= MAX_KEY_TEXT_SIZE
    @key_text
  else
    @entity.to_s
  end
end

#key_widthObject


43
44
45
46
47
48
49
# File 'lib/gitlab/badge/pipeline/template.rb', line 43

def key_width
  if @key_width && @key_width.between?(1, MAX_KEY_WIDTH)
    @key_width
  else
    62
  end
end

#value_colorObject


55
56
57
# File 'lib/gitlab/badge/pipeline/template.rb', line 55

def value_color
  STATUS_COLOR[@status.to_sym] || STATUS_COLOR[:unknown]
end

#value_textObject


39
40
41
# File 'lib/gitlab/badge/pipeline/template.rb', line 39

def value_text
  STATUS_RENAME[@status.to_s] || @status.to_s
end

#value_widthObject


51
52
53
# File 'lib/gitlab/badge/pipeline/template.rb', line 51

def value_width
  54
end