Skip to content

Commit

Permalink
Refactor url methods a bit
Browse files Browse the repository at this point in the history
Use if..else conditions instead of return guards.
Use _ for not used arguments when iterating.
Set the path variable directly instead of using an empty string and <<.
  • Loading branch information
carlosantoniodasilva committed Nov 16, 2012
1 parent 8e49fa6 commit f73a05f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions actionpack/lib/action_dispatch/http/url.rb
Expand Up @@ -8,30 +8,30 @@ module URL

class << self
def extract_domain(host, tld_length = @@tld_length)
return nil unless named_host?(host)
host.split('.').last(1 + tld_length).join('.')
host.split('.').last(1 + tld_length).join('.') if named_host?(host)
end

def extract_subdomains(host, tld_length = @@tld_length)
return [] unless named_host?(host)
parts = host.split('.')
parts[0..-(tld_length+2)]
if named_host?(host)
parts = host.split('.')
parts[0..-(tld_length + 2)]
else
[]
end
end

def extract_subdomain(host, tld_length = @@tld_length)
extract_subdomains(host, tld_length).join('.')
end

def url_for(options = {})
path = ""
path << options.delete(:script_name).to_s.chomp("/")
path = options.delete(:script_name).to_s.chomp("/")
path << options.delete(:path).to_s

params = options[:params] || {}
params.reject! {|k,v| v.to_param.nil? }
params.reject! { |_,v| v.to_param.nil? }

result = build_host_url(options)

result << (options[:trailing_slash] ? path.sub(/\?|\z/) { "/" + $& } : path)
result << "?#{params.to_query}" unless params.empty?
result << "##{Journey::Router::Utils.escape_fragment(options[:anchor].to_param.to_s)}" if options[:anchor]
Expand Down

0 comments on commit f73a05f

Please sign in to comment.