module SubdomainRouter::Constraint
A routing constraint that restricts routes to only valid dynamic subdomains.
@example
get 'home' => 'accounts#show', constraint: SubdomainRouter::Constraint
Public Class Methods
matches?(request)
click to toggle source
Determines if a given request has a custom user subdomain.
@param [ActionDispatch::Request] request An HTTP request. @return [true, false] Whether the request subdomain matches a known user
subdomain.
# File lib/subdomain_router.rb, line 60 def matches?(request) return false unless request.subdomains.size == 1 return false if request.subdomains.first == Config.default_subdomain return subdomain?(request) end
subdomain?(request)
click to toggle source
# File lib/subdomain_router.rb, line 69 def subdomain?(request) subdomain = request.subdomains.first.downcase Config.subdomain_matcher.(subdomain, request) end
Private Instance Methods
matches?(request)
click to toggle source
Determines if a given request has a custom user subdomain.
@param [ActionDispatch::Request] request An HTTP request. @return [true, false] Whether the request subdomain matches a known user
subdomain.
# File lib/subdomain_router.rb, line 60 def matches?(request) return false unless request.subdomains.size == 1 return false if request.subdomains.first == Config.default_subdomain return subdomain?(request) end
subdomain?(request)
click to toggle source
# File lib/subdomain_router.rb, line 69 def subdomain?(request) subdomain = request.subdomains.first.downcase Config.subdomain_matcher.(subdomain, request) end