|
|
|
@@ -48,7 +48,7 @@ class Tag < ApplicationRecord |
|
|
|
validate :tag_name_must_be_canonical |
|
|
|
validate :category_must_be_deerjikist_with_deerjikists |
|
|
|
|
|
|
|
scope :nico_tags, -> { where(category: :nico) } |
|
|
|
scope :nico_tags, -> { nico } |
|
|
|
|
|
|
|
CATEGORY_PREFIXES = { |
|
|
|
'general:' => :general, |
|
|
|
@@ -97,14 +97,12 @@ class Tag < ApplicationRecord |
|
|
|
pf, cat = CATEGORY_PREFIXES.find { |p, _| name.downcase.start_with?(p) } || ['', nil] |
|
|
|
name = TagName.canonicalise(name.sub(/\A#{ pf }/i, '')).first |
|
|
|
find_or_create_by_tag_name!(name, category: (cat || :general)).tap do |tag| |
|
|
|
if cat && tag.category != cat |
|
|
|
tag.update!(category: cat) |
|
|
|
end |
|
|
|
tag.update!(category: cat) if cat && tag.category != cat |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
tags << Tag.tagme if with_tagme && tags.size < 10 && tags.none?(Tag.tagme) |
|
|
|
tags << Tag.no_deerjikist if tags.all? { |t| t.category != 'deerjikist' } |
|
|
|
tags << Tag.no_deerjikist if tags.all? { |t| !(t.deerjikist?) } |
|
|
|
tags.uniq(&:id) |
|
|
|
end |
|
|
|
|
|
|
|
@@ -166,19 +164,20 @@ class Tag < ApplicationRecord |
|
|
|
tag_name.reload |
|
|
|
tag_name.update!(canonical: target_tag.tag_name) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
target_tag.update!(post_count: PostTag.kept.where(tag: target_tag).count) |
|
|
|
# 再集計 |
|
|
|
target_tag.update_columns(post_count: PostTag.kept.where(tag: target_tag).count) |
|
|
|
end |
|
|
|
|
|
|
|
target_tag |
|
|
|
target_tag.reload |
|
|
|
end |
|
|
|
|
|
|
|
private |
|
|
|
|
|
|
|
def nico_tag_name_must_start_with_nico |
|
|
|
n = name.to_s |
|
|
|
if ((category == 'nico' && !(n.downcase.start_with?('nico:'))) || |
|
|
|
(category != 'nico' && n.downcase.start_with?('nico:'))) |
|
|
|
if ((nico? && !(n.downcase.start_with?('nico:'))) || |
|
|
|
(!(nico?) && n.downcase.start_with?('nico:'))) |
|
|
|
errors.add :name, 'ニコニコ・タグの命名規則に反してゐます.' |
|
|
|
end |
|
|
|
end |
|
|
|
|