Permalink
Browse files

reduce calls to `named_host?`

`normalize_host` already calls `named_host?`, so there is no reason to
test `named_host?` again in the `extract_domain` method.
  • Loading branch information...
1 parent caf1bfc commit 21c626133adc4b5060df1081d9423024b6b7479d @tenderlove tenderlove committed Jun 12, 2014
Showing with 6 additions and 2 deletions.
  1. +6 −2 actionpack/lib/action_dispatch/http/url.rb
View
8 actionpack/lib/action_dispatch/http/url.rb
@@ -13,7 +13,7 @@ module URL
class << self
def extract_domain(host, tld_length)
- host.split('.').last(1 + tld_length).join('.') if named_host?(host)
+ extract_domain_from(host, tld_length) if named_host?(host)
end
def extract_subdomains(host, tld_length)
@@ -60,6 +60,10 @@ def url_for(options)
private
+ def extract_domain_from(host, tld_length)
+ host.split('.').last(1 + tld_length).join('.')
+ end
+
def add_trailing_slash(path)
# includes querysting
if path.include?('?')
@@ -131,7 +135,7 @@ def normalize_host(_host, options)
host << subdomain.to_param
end
host << "." unless host.empty?
- host << (options[:domain] || extract_domain(_host, tld_length))
+ host << (options[:domain] || extract_domain_from(_host, tld_length))
host
end

0 comments on commit 21c6261

Please sign in to comment.