From 86e4c21e48c7fde5fd7f755715314cc5cbaee540 Mon Sep 17 00:00:00 2001
From: evazion
Date: Wed, 2 Dec 2020 12:49:14 -0600
Subject: [PATCH] implications: refactor automatic tags.
Move #automatic_tags_for out of TagImplication since it doesn't really
belong here.
---
app/models/post.rb | 2 +-
app/models/tag.rb | 8 +++++++
app/models/tag_implication.rb | 22 ++-----------------
.../_alias_and_implication_list.html.erb | 2 +-
4 files changed, 12 insertions(+), 22 deletions(-)
diff --git a/app/models/post.rb b/app/models/post.rb
index 0c89dffbb..8a33ac746 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -478,7 +478,7 @@ class Post < ApplicationRecord
normalized_tags = add_automatic_tags(normalized_tags)
normalized_tags = remove_invalid_tags(normalized_tags)
normalized_tags = Tag.convert_cosplay_tags(normalized_tags)
- normalized_tags += Tag.create_for_list(TagImplication.automatic_tags_for(normalized_tags))
+ normalized_tags += Tag.create_for_list(Tag.automatic_tags_for(normalized_tags))
normalized_tags += TagImplication.tags_implied_by(normalized_tags).map(&:name)
normalized_tags = normalized_tags.compact.uniq.sort
normalized_tags = Tag.create_for_list(normalized_tags)
diff --git a/app/models/tag.rb b/app/models/tag.rb
index f018c2dbf..c9ca52da9 100644
--- a/app/models/tag.rb
+++ b/app/models/tag.rb
@@ -335,6 +335,14 @@ class Tag < ApplicationRecord
end
end
+ def self.automatic_tags_for(names)
+ tags = []
+ tags += names.grep(/\A(.+)_\(cosplay\)\z/i) { "char:#{TagAlias.to_aliased([$1]).first}" }
+ tags << "cosplay" if names.any?(/_\(cosplay\)\z/i)
+ tags << "school_uniform" if names.any?(/_school_uniform\z/i)
+ tags.uniq
+ end
+
def self.convert_cosplay_tags(tags)
cosplay_tags, other_tags = tags.partition {|tag| tag.match(/\A(.+)_\(cosplay\)\Z/) }
cosplay_tags.grep(/\A(.+)_\(cosplay\)\Z/) { "#{TagAlias.to_aliased([$1]).first}_(cosplay)" } + other_tags
diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb
index ccb889d55..6c5da1d4f 100644
--- a/app/models/tag_implication.rb
+++ b/app/models/tag_implication.rb
@@ -8,20 +8,6 @@ class TagImplication < TagRelationship
validate :antecedent_is_not_aliased
validate :consequent_is_not_aliased
- module DescendantMethods
- extend ActiveSupport::Concern
-
- module ClassMethods
- def automatic_tags_for(names)
- tags = []
- tags += names.grep(/\A(.+)_\(cosplay\)\z/i) { "char:#{TagAlias.to_aliased([$1]).first}" }
- tags << "cosplay" if names.any?(/_\(cosplay\)\z/i)
- tags << "school_uniform" if names.any?(/_school_uniform\z/i)
- tags.uniq
- end
- end
- end
-
concerning :HierarchyMethods do
class_methods do
def ancestors_of(names)
@@ -64,7 +50,7 @@ class TagImplication < TagRelationship
end
end
- module ValidationMethods
+ concerning :ValidationMethods do
def absence_of_circular_relation
return if is_rejected?
@@ -107,7 +93,7 @@ class TagImplication < TagRelationship
end
end
- module ApprovalMethods
+ concerning :ApprovalMethods do
def process!
update_posts!
end
@@ -121,8 +107,4 @@ class TagImplication < TagRelationship
end
end
end
-
- include DescendantMethods
- include ValidationMethods
- include ApprovalMethods
end
diff --git a/app/views/tag_relationships/_alias_and_implication_list.html.erb b/app/views/tag_relationships/_alias_and_implication_list.html.erb
index 94e24d864..dc66fff98 100644
--- a/app/views/tag_relationships/_alias_and_implication_list.html.erb
+++ b/app/views/tag_relationships/_alias_and_implication_list.html.erb
@@ -14,7 +14,7 @@
<% end %>
- <% TagImplication.automatic_tags_for([tag.name]).tap do |automatic_tags| %>
+ <% Tag.automatic_tags_for([tag.name]).tap do |automatic_tags| %>
<% if automatic_tags.present? %>
This tag automatically adds