Created
December 13, 2011 06:32
-
-
Save mipearson/1470906 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def subdomain | |
| @subdomain ||= begin | |
| parts = begin | |
| if @request.host.ends_with?('.au') | |
| @request.subdomains(2) | |
| else | |
| @request.subdomains(1) | |
| end | |
| end | |
| parts.first == 'www' ? parts[1] : parts[0] | |
| end | |
| end | |
Author
use a return-if construct, it's not as bad as it sounds
def subdomain
return @subdomain if @subdomain
parts = @request.subdomains(@request.host[-3, 3] == '.au' ? 2 : 1)
@subdomain = parts.first == 'www' ? parts[1] : parts[0]
endor use 'public_suffix_service' gem
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(yes, it has unit tests)