diff --git a/app/models/public_body/calculated_home_page.rb b/app/models/public_body/calculated_home_page.rb index 27461f5fe8..9e41cab920 100644 --- a/app/models/public_body/calculated_home_page.rb +++ b/app/models/public_body/calculated_home_page.rb @@ -22,12 +22,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 @@ -36,8 +39,6 @@ def calculated_home_page end end - private - def excluded_calculated_home_page_domain?(domain) excluded_calculated_home_page_domains.include?(domain) end