From 4fde2a26fb215cc067f146a5f4824f6ed7eb82c5 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 23 Mar 2017 02:48:03 -0500 Subject: [PATCH] post.rb: handle automatic *_(cosplay) tags in TagImplication. --- app/models/post.rb | 5 +---- app/models/tag_implication.rb | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index cb14a1792..d8053308a 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -636,6 +636,7 @@ class Post < ActiveRecord::Base normalized_tags = %w(tagme) if normalized_tags.empty? normalized_tags = TagAlias.to_aliased(normalized_tags) normalized_tags = add_automatic_tags(normalized_tags) + normalized_tags = normalized_tags + TagImplication.automatic_tags_for(normalized_tags) normalized_tags = TagImplication.with_descendants(normalized_tags) normalized_tags = normalized_tags.compact normalized_tags.sort! @@ -705,10 +706,6 @@ class Post < ActiveRecord::Base tags << "ugoira" end - characters = tags.grep(/\A(.+)_\(cosplay\)\Z/) { $1 } - tags += characters - tags << "cosplay" if characters.present? - return tags end diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index 96d2a58b3..cae1ff91b 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -32,6 +32,12 @@ class TagImplication < ActiveRecord::Base def with_descendants(names) (names + where("antecedent_name in (?) and status in (?)", names, ["active", "processing"]).map(&:descendant_names_array)).flatten.uniq end + + def automatic_tags_for(names) + tags = names.grep(/\A(.+)_\(cosplay\)\Z/) { $1 } + tags << "cosplay" if tags.present? + tags.uniq + end end def descendants