implications: refactor automatic tags.
Move #automatic_tags_for out of TagImplication since it doesn't really belong here.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
</p>
|
||||
<% 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? %>
|
||||
<p class="fineprint">
|
||||
This tag automatically adds
|
||||
|
||||
Reference in New Issue
Block a user