|
|
|
@ -17,10 +17,10 @@ class Tag < ApplicationRecord
|
|
|
|
|
has_many :featured_tags, dependent: :destroy, inverse_of: :tag
|
|
|
|
|
has_one :account_tag_stat, dependent: :destroy
|
|
|
|
|
|
|
|
|
|
HASHTAG_NAME_RE = '[[:word:]_][[:word:]_]*[[:alpha:]_·]*[[:word:]_·]*[[:word:]_]'
|
|
|
|
|
HASHTAG_NAME_RE = '([[:word:]_][[:word:]_·]*[[:alpha:]_·][[:word:]_·]*[[:word:]_])|([[:word:]_]*[[:alpha:]][[:word:]_]*)'
|
|
|
|
|
HASHTAG_RE = /(?:^|[^\/\)\w])#(#{HASHTAG_NAME_RE})/i
|
|
|
|
|
|
|
|
|
|
validates :name, presence: true, uniqueness: true, format: { with: /\A#{HASHTAG_NAME_RE}\z/i }
|
|
|
|
|
validates :name, presence: true, uniqueness: true, format: { with: /\A(#{HASHTAG_NAME_RE})\z/i }
|
|
|
|
|
|
|
|
|
|
scope :discoverable, -> { joins(:account_tag_stat).where(AccountTagStat.arel_table[:accounts_count].gt(0)).where(account_tag_stats: { hidden: false }).order(Arel.sql('account_tag_stats.accounts_count desc')) }
|
|
|
|
|
scope :hidden, -> { where(account_tag_stats: { hidden: true }) }
|
|
|
|
|