Methods
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)
Link
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"
extract_subdomain(host, tld_length)
Link
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"
extract_subdomains(host, tld_length)
Link
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"]
full_url_for(options)
Link
# 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)
Link
# 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