From 7770c38d0d2ff65d1a22301127bd581113271401 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 27 Aug 2020 21:39:49 -0500 Subject: [PATCH] saved searches: rearrange macros. Move macros to the top of file, as they should be. --- app/models/saved_search.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/models/saved_search.rb b/app/models/saved_search.rb index 53b664163..df4c2dddc 100644 --- a/app/models/saved_search.rb +++ b/app/models/saved_search.rb @@ -2,6 +2,17 @@ class SavedSearch < ApplicationRecord REDIS_EXPIRY = 1.hour QUERY_LIMIT = 1000 + attr_reader :disable_labels + belongs_to :user + + before_validation :normalize_query + before_validation :normalize_labels + validates :query, presence: true + validate :validate_count + + scope :labeled, ->(label) { where_array_includes_any_lower(:labels, [normalize_label(label)]) } + scope :has_tag, ->(name) { where_regex(:query, "(^| )[~-]?#{Regexp.escape(name)}( |$)", flags: "i") } + concerning :Redis do extend Memoist @@ -161,15 +172,6 @@ class SavedSearch < ApplicationRecord end end - attr_reader :disable_labels - belongs_to :user - validates :query, presence: true - validate :validate_count - before_validation :normalize_query - before_validation :normalize_labels - scope :labeled, ->(label) { where_array_includes_any_lower(:labels, [normalize_label(label)]) } - scope :has_tag, ->(name) { where_regex(:query, "(^| )[~-]?#{Regexp.escape(name)}( |$)", flags: "i") } - def validate_count if user.saved_searches.count + 1 > user.max_saved_searches self.errors[:user] << "can only have up to #{user.max_saved_searches} " + "saved search".pluralize(user.max_saved_searches)