From 040e10a6275e687452ef2119de1cd93bc3fa5854 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Wed, 15 Feb 2017 17:27:10 -0500 Subject: [PATCH] reduce duplication --- app/controllers/list_controller.rb | 7 +---- lib/topic_query.rb | 46 ++++++++++++++++++------------ 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index 898699692c6..fe8d4d44629 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -278,7 +278,7 @@ class ListController < ApplicationController def build_topic_list_options options = {} - TopicQuery.valid_options.each do |key| + TopicQuery.public_valid_options.each do |key| options[key] = params[key] end @@ -286,11 +286,6 @@ class ListController < ApplicationController options[:topic_ids] = param_to_integer_list(:topic_ids) options[:no_subcategories] = options[:no_subcategories] == 'true' options[:slow_platform] = slow_platform? - options.delete(:per_page) - options.delete(:limit) - options.delete(:except_topic_ids) - options.delete(:visible) - options.delete(:no_definitions) options end diff --git a/lib/topic_query.rb b/lib/topic_query.rb index a1a8818dacd..0f754b6007b 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -10,32 +10,38 @@ require_dependency 'avatar_lookup' class TopicQuery + def self.public_valid_options + @public_valid_options ||= + %i(page + topic_ids + exclude_category_ids + category + order + ascending + min_posts + max_posts + status + filter + state + search + q + group_name + tags + match_all_tags + no_subcategories + slow_platform + no_tags) + end + def self.valid_options @valid_options ||= + public_valid_options + %i(except_topic_ids - exclude_category_ids limit page per_page - min_posts - max_posts - topic_ids visible - category - tags - match_all_tags - no_tags - order - ascending - no_subcategories - no_definitions - status - state - search - slow_platform - filter - group_name - q) + no_definitions) end @@ -59,11 +65,13 @@ class TopicQuery def self.add_custom_filter(key, &blk) @custom_filters ||= {} valid_options << key + public_valid_options << key @custom_filters[key] = blk end def self.remove_custom_filter(key) @custom_filters.delete(key) + public_valid_options.delete(key) valid_options.delete(key) @custom_filters = nil if @custom_filters.length == 0 end