From 44e89271fe03aa6a863fbe283f69abcb5f6a34a2 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 4 Oct 2018 09:29:06 +0200 Subject: [PATCH] Refactoring: Momorize result and more idiomatic ruby. --- lib/models.rb | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/lib/models.rb b/lib/models.rb index e750b2219..e613f20b8 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -71,13 +71,7 @@ returns =end def self.searchable - models = [] - all.each_key do |model_class| - next if !model_class - next if !model_class.respond_to? :search_preferences - models.push model_class - end - models + @searchable ||= Models.all.keys.select { |model| model.respond_to?(:search_preferences) } end =begin @@ -93,13 +87,7 @@ returns =end def self.indexable - models = [] - all.each_key do |model_class| - next if !model_class - next if !model_class.new.respond_to? :search_index_update_backend - models.push model_class - end - models + @indexable ||= Models.all.keys.select { |model| model.method_defined?(:search_index_update_backend) } end =begin