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_title' => :title,
  'project_name' => :path,
  'project_id' => :id,
  'project_namespace' => ->(project) { project.project_namespace.to_param },
  'group_name' => ->(project) { project.group&.to_param },
  'gitlab_server' => proc { Gitlab.config.gitlab.host },
  'gitlab_pages_domain' => proc { Gitlab.config.pages.host },
  'default_branch' => :default_branch,
  'commit_sha' => ->(project) { project.commit&.sha },
  'latest_tag' => ->(project) do
    TagsFinder.new(project.repository, per_page: 1, sort: 'updated_desc').execute.first&.name if project.repository
  end
}.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('|')})/

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

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, nullable_column?, 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 ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Instance Method Details

#rendered_image_url(project = nil) ⇒ Object



43
44
45
46
47
# File 'app/models/badge.rb', line 43

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


39
40
41
# File 'app/models/badge.rb', line 39

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