Skip to content

Commit

Permalink
Add PublicBody#calculated_home_page!
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
garethrees committed Jul 24, 2023
1 parent 152b084 commit 1ed39c6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/models/public_body/calculated_home_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1ed39c6

Please sign in to comment.