From 8aa79ac6c418fbb4fba0a429bbc30bf13e7fe92b Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Mon, 24 Jul 2023 10:13:28 +0100 Subject: [PATCH] Add PublicBody#calculated_home_page! Removes the TODO by adding a cached and non-cached version of PublicBody::CalculatedHomePage#calculated_home_page. In current use it's safe to always use the cached version. In future we might want to modify the non-bang version such that it recalculates if the request_email attribute gets changed. --- app/models/public_body/calculated_home_page.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/models/public_body/calculated_home_page.rb b/app/models/public_body/calculated_home_page.rb index fb8143b3cd..f517a31e84 100644 --- a/app/models/public_body/calculated_home_page.rb +++ b/app/models/public_body/calculated_home_page.rb @@ -25,12 +25,15 @@ module PublicBody::CalculatedHomePage ] end + def calculated_home_page + @calculated_home_page ||= calculated_home_page! + end + + private + # Guess home page from the request email, or use explicit override, or nil # if not known. - # - # TODO: PublicBody#calculated_home_page would be a good candidate to cache - # in an instance variable - def calculated_home_page + def calculated_home_page! if home_page && !home_page.empty? home_page[URI.regexp(%w(http https))] ? home_page : "https://#{home_page}" elsif request_email_domain @@ -39,8 +42,6 @@ def calculated_home_page end end - private - def excluded_calculated_home_page_domain?(domain) excluded_calculated_home_page_domains.include?(domain) end