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

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Instance Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

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