edge badge
Methods
E
F
P
U
Constants
HOST_REGEXP = /(^[^:]+:\/\/)?(\[[^\]]+\]|[^:]+)(?::(\d+$))?/
 
IP_HOST_REGEXP = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
 
PROTOCOL_REGEXP = /^([^:]+)(:)?(\/\/)?$/
 
Class Public methods
extract_domain(host, tld_length)

Returns the domain part of a host given the domain level.

# Top-level domain example
extract_domain('www.example.com', 1) # => "example.com"
# Second-level domain example
extract_domain('dev.www.example.co.uk', 2) # => "example.co.uk"
# File actionpack/lib/action_dispatch/http/url.rb, line 21
def extract_domain(host, tld_length)
  extract_domain_from(host, tld_length) if named_host?(host)
end
extract_subdomain(host, tld_length)

Returns the subdomains of a host as a String given the domain level.

# Top-level domain example
extract_subdomain('www.example.com', 1) # => "www"
# Second-level domain example
extract_subdomain('dev.www.example.co.uk', 2) # => "dev.www"
# File actionpack/lib/action_dispatch/http/url.rb, line 45
def extract_subdomain(host, tld_length)
  extract_subdomains(host, tld_length).join(".")
end
extract_subdomains(host, tld_length)

Returns the subdomains of a host as an Array given the domain level.

# Top-level domain example
extract_subdomains('www.example.com', 1) # => ["www"]
# Second-level domain example
extract_subdomains('dev.www.example.co.uk', 2) # => ["dev", "www"]
# File actionpack/lib/action_dispatch/http/url.rb, line 31
def extract_subdomains(host, tld_length)
  if named_host?(host)
    extract_subdomains_from(host, tld_length)
  else
    []
  end
end
full_url_for(options)
# File actionpack/lib/action_dispatch/http/url.rb, line 57
def full_url_for(options)
  host     = options[:host]
  protocol = options[:protocol]
  port     = options[:port]

  unless host
    raise ArgumentError, "Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true"
  end

  build_host_url(host, port, protocol, options, path_for(options))
end
path_for(options)
# File actionpack/lib/action_dispatch/http/url.rb, line 69
def path_for(options)
  path = options[:script_name].to_s.chomp("/".freeze)
  path << options[:path] if options.key?(:path)

  add_trailing_slash(path) if options[:trailing_slash]
  add_params(path, options[:params]) if options.key?(:params)
  add_anchor(path, options[:anchor]) if options.key?(:anchor)

  path
end
url_for(options)
# File actionpack/lib/action_dispatch/http/url.rb, line 49
def url_for(options)
  if options[:only_path]
    path_for options
  else
    full_url_for options
  end
end