Class: EnsureSubdomain
- Inherits:
-
Object
- Object
- EnsureSubdomain
- Defined in:
- lib/ensure_subdomain.rb,
lib/ensure_subdomain/version.rb
Defined Under Namespace
Modules: VERSION
Instance Attribute Summary collapse
-
#subdomains ⇒ Object
Returns the value of attribute subdomains.
Instance Method Summary collapse
-
#initialize(subdomains) ⇒ EnsureSubdomain
constructor
A new instance of EnsureSubdomain.
- #matches?(request) ⇒ Boolean
-
#to(params, request) ⇒ Object
Only called when not on an appropriate domain.
Constructor Details
#initialize(subdomains) ⇒ EnsureSubdomain
Returns a new instance of EnsureSubdomain.
6 7 8 9 |
# File 'lib/ensure_subdomain.rb', line 6 def initialize(subdomains) subdomains = [subdomains] unless subdomains.respond_to?(:map) self.subdomains = subdomains.map { |s| s.sub(/\.$/, '') } end |
Instance Attribute Details
#subdomains ⇒ Object
Returns the value of attribute subdomains.
4 5 6 |
# File 'lib/ensure_subdomain.rb', line 4 def subdomains @subdomains end |
Instance Method Details
#matches?(request) ⇒ Boolean
11 12 13 14 |
# File 'lib/ensure_subdomain.rb', line 11 def matches?(request) # Don't deal with addresses like http://0.0.0.0:3000 request.domain.present? and requires_redirect?(request) end |
#to(params, request) ⇒ Object
Only called when not on an appropriate domain
17 18 19 20 21 22 |
# File 'lib/ensure_subdomain.rb', line 17 def to(params, request) url = request.protocol url << redirect_to_full_domain(request) url << "/#{params[:path]}" if params[:path].present? url end |