diff --git a/app/models/communication/block/template/post.rb b/app/models/communication/block/template/post.rb index d474d433b7d2335488fee762b7f229330970c734..7f5c803c0d045307e500187b3d2da88811bcfe10 100644 --- a/app/models/communication/block/template/post.rb +++ b/app/models/communication/block/template/post.rb @@ -16,13 +16,7 @@ class Communication::Block::Template::Post < Communication::Block::Template end def selected_posts - if kind == 'all' - @selected_posts ||= all_posts - elsif kind == 'selection' - @selected_posts ||= free_posts - elsif kind == 'category' - @selected_posts ||= category_posts - end + @selected_posts ||= send "selected_posts_#{kind}" end protected @@ -31,17 +25,17 @@ class Communication::Block::Template::Post < Communication::Block::Template @kind ||= data['kind'] || 'all' end - def all_posts + def selected_posts_all quantity = data['posts_quantity'] || 3 block.about&.website.posts.ordered.limit(quantity) end - def category_posts + def selected_posts_category quantity = data['posts_quantity'] || 3 category.posts.ordered.limit(quantity) end - def free_posts + def selected_posts_free elements.map { |element| post(element['id']) } .compact end