From d461bb2ad059cae2f72192221af705f85a5bb1e1 Mon Sep 17 00:00:00 2001
From: evazion
Date: Fri, 17 Jan 2020 02:13:10 -0600
Subject: [PATCH] post sets: refactor pool/favgroup methods.
Eliminate the `has_pool?` and `pool_name` methods in favor of the `pool`
method. Likewise for favgroups.
---
app/logical/post_sets/post.rb | 24 ++++++-------------
app/views/posts/index.html.erb | 4 ++--
.../posts/partials/index/_excerpt.html.erb | 4 ++--
3 files changed, 11 insertions(+), 21 deletions(-)
diff --git a/app/logical/post_sets/post.rb b/app/logical/post_sets/post.rb
index d7078ffe6..2c476bc2d 100644
--- a/app/logical/post_sets/post.rb
+++ b/app/logical/post_sets/post.rb
@@ -41,28 +41,18 @@ module PostSets
tag.artist
end
- def pool_name
- @pool_name ||= Tag.has_metatag?(tag_array, :ordpool, :pool)
- end
-
- def has_pool?
- is_single_tag? && pool_name && pool
- end
-
def pool
- ::Pool.find_by_name(pool_name)
- end
+ name = Tag.has_metatag?(tag_array, :ordpool, :pool)
+ return nil unless is_single_tag? && name.present?
- def favgroup_name
- @favgroup_name ||= Tag.has_metatag?(tag_array, :favgroup)
- end
-
- def has_favgroup?
- is_single_tag? && favgroup_name && favgroup
+ @pool ||= Pool.find_by_name(name)
end
def favgroup
- ::FavoriteGroup.find_by_name(favgroup_name)
+ name = Tag.has_metatag?(tag_array, :favgroup)
+ return nil unless is_single_tag? && name.present?
+
+ @favgroup ||= FavoriteGroup.find_by_name(name)
end
def has_explicit?
diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb
index e1150f9ce..9c29976ea 100644
--- a/app/views/posts/index.html.erb
+++ b/app/views/posts/index.html.erb
@@ -30,9 +30,9 @@
<%= link_to "Artist", artist_path(@post_set.artist), :id => "show-excerpt-link" %>
<% elsif @post_set.wiki_page.present? %>
<%= link_to "Wiki", wiki_page_path(@post_set.wiki_page), :id => "show-excerpt-link" %>
- <% elsif @post_set.has_pool? %>
+ <% elsif @post_set.pool.present? %>
<%= link_to "Pool", pool_path(@post_set.pool), :id => "show-excerpt-link" %>
- <% elsif @post_set.has_favgroup? %>
+ <% elsif @post_set.favgroup.present? %>
<%= link_to "Favorite Group", favorite_group_path(@post_set.favgroup), :id => "show-excerpt-link" %>
<% elsif @post_set.has_blank_wiki? %>
<%= link_to "Wiki", new_wiki_page_path(wiki_page: { title: @post_set.tag_string }), id: "show-excerpt-link" %>
diff --git a/app/views/posts/partials/index/_excerpt.html.erb b/app/views/posts/partials/index/_excerpt.html.erb
index ddcaa683c..5773c7b37 100644
--- a/app/views/posts/partials/index/_excerpt.html.erb
+++ b/app/views/posts/partials/index/_excerpt.html.erb
@@ -36,7 +36,7 @@
<% end %>
- <% elsif post_set.has_pool? %>
+ <% elsif post_set.pool.present? %>
<% post_set.pool.tap do |pool| %>
<%= pool.pretty_category %>:
@@ -54,7 +54,7 @@
<%= link_to "View pool", pool_path(post_set.pool.id) %>
<% end %>
- <% elsif post_set.has_favgroup? %>
+ <% elsif post_set.favgroup.present? %>
Favorite Group:
<%= link_to post_set.favgroup.pretty_name, favorite_group_path(post_set.favgroup) %>