Class: Badge

Inherits:
ApplicationRecord show all
Includes:
FromUnion
Defined in:
app/models/badge.rb

Direct Known Subclasses

GroupBadge, ProjectBadge

Constant Summary collapse

PLACEHOLDERS =

This structure sets the placeholders that the urls can have. This hash also sets which action to ask when the placeholder is found.

{
  'project_path' => :full_path,
  'project_id' => :id,
  'default_branch' => :default_branch,
  'commit_sha' => ->(project) { project.commit&.sha }
}.freeze
PLACEHOLDERS_REGEX =

This regex is built dynamically using the keys from the PLACEHOLDER struct. So, we can easily add new placeholder just by modifying the PLACEHOLDER hash. This regex will build the new PLACEHOLDER_REGEX with the new information

/(#{PLACEHOLDERS.keys.join('|')})/.freeze

Instance Method Summary collapse

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Instance Method Details

#rendered_image_url(project = nil) ⇒ Object


34
35
36
37
38
# File 'app/models/badge.rb', line 34

def rendered_image_url(project = nil)
  Gitlab::AssetProxy.proxy_url(
    build_rendered_url(image_url, project)
  )
end

30
31
32
# File 'app/models/badge.rb', line 30

def rendered_link_url(project = nil)
  build_rendered_url(link_url, project)
end