debian-mirror-gitlab/app/models/programming_language.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
858 B
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2019-07-07 11:18:12 +05:30
class ProgrammingLanguage < ApplicationRecord
2018-11-18 11:00:15 +05:30
validates :name, presence: true
validates :color, allow_blank: false, color: true
2019-03-02 22:35:43 +05:30
2022-06-21 17:19:12 +05:30
# Returns all programming languages which match any of the given names (case
2019-03-02 22:35:43 +05:30
# insensitively).
2022-06-21 17:19:12 +05:30
scope :with_name_case_insensitive, ->(*names) do
sanitized_names = names.map(&method(:sanitize_sql_like))
where(arel_table[:name].matches_any(sanitized_names))
2019-03-02 22:35:43 +05:30
end
2023-03-04 22:38:38 +05:30
def self.most_popular(limit = 25)
sql = <<~SQL
SELECT
mcv
FROM
pg_stats
CROSS JOIN LATERAL
unnest(most_common_vals::text::int[]) mt(mcv)
WHERE
tablename = 'repository_languages' and attname='programming_language_id'
LIMIT
$1
SQL
ids = connection.exec_query(sql, 'SQL', [limit]).rows.flatten
where(id: ids).order(:name)
end
2018-11-18 11:00:15 +05:30
end