このコミットが含まれているのは:
2026-09-27 17:13:02 +09:00
コミット 56205b7052
3個のファイルの変更、104行の追加、67行の削除
+9 -21
ファイルの表示
@@ -51,12 +51,9 @@ class Tag < ApplicationRecord
has_many :tag_versions
has_many :tag_names
delegate :wiki_page, to: :tag_name
attribute :version_no, :integer, default: 1
validates :tag_name, presence: true
enum :category, deerjikist: 'deerjikist',
meme: 'meme',
character: 'character',
@@ -66,8 +63,6 @@ class Tag < ApplicationRecord
validates :category, presence: true, inclusion: { in: Tag.categories.keys }
validate :tag_name_mustnt_start_with_nico
validate :tag_name_must_be_canonical
validate :category_must_be_deerjikist_with_deerjikists
CATEGORY_PREFIXES = {
@@ -84,6 +79,7 @@ class Tag < ApplicationRecord
def tag_name(language_code) = tag_names.find_by(language_code:, primary_flg: true)
def name(language_code) = tag_name(language_code)&.name
def wiki_page = WikiPage.find_by(tag_name_id: id)
def deprecated? = deprecated_at?
@@ -234,7 +230,7 @@ class Tag < ApplicationRecord
tag = tn.tag
return tag if tag
tag = Tag.create!(tag_name: tn, category:)
tag = Tag.create!(tag_name_id: tn.id, category:)
tn.update!(tag:)
tag
@@ -295,28 +291,20 @@ class Tag < ApplicationRecord
target_tag.reload
end
def snapshot_aliases = tag_name.aliases.order(:name).pluck(:name)
def snapshot_aliases(language_code) = tag_name(language_code).aliases.order(:name).pluck(:name)
def snapshot_parent_tag_ids = parents.order(:id).pluck(:id)
def snapshot_linked_tag_names
linked_tags.joins(:tag_name).order('tag_names.name').pluck('tag_names.name')
def snapshot_linked_tag_names language_code
linked_tags
.joins(:tag_names)
.where(tag_names: { language_code:, primary_flg: true })
.order('tag_names.name')
.pluck('tag_names.name')
end
private
def tag_name_mustnt_start_with_nico
if name.to_s.downcase.start_with?('nico:')
errors.add :name, 'タグの命名規則に反してゐます.'
end
end
def tag_name_must_be_canonical
if tag_name&.canonical_id?
errors.add :tag_name, 'tag_names へは実体を示す必要があります.'
end
end
def category_must_be_deerjikist_with_deerjikists
if !(deerjikist?) && deerjikists.exists?
errors.add :category, 'ニジラーと紐づいてゐるタグはニジラー・カテゴリである必要があります.'
+7
ファイルの表示
@@ -10,6 +10,7 @@ class TagName < ApplicationRecord
validate :alias_name_must_not_have_prefix
validate :alias_must_not_have_wiki_page
validate :name_must_be_sanitised
validate :name_mustnt_start_with_nico
def primary? = primary_flg
@@ -58,4 +59,10 @@ class TagName < ApplicationRecord
errors.add :name, '名前に使用できない文字が含まれてゐます.'
end
end
def name_mustnt_start_with_nico
if name.to_s.downcase.start_with?('nico:')
errors.add :name, 'タグの命名規則に反してゐます.'
end
end
end