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
-
#subdomain ⇒ Object
Returns the value of attribute subdomain.
Instance Method Summary collapse
-
#initialize(subdomain) ⇒ EnsureSubdomain
constructor
A new instance of EnsureSubdomain.
- #matches?(request) ⇒ Boolean
- #to(params, request) ⇒ Object
Constructor Details
#initialize(subdomain) ⇒ EnsureSubdomain
Returns a new instance of EnsureSubdomain.
4 5 6 |
# File 'lib/ensure_subdomain.rb', line 4 def initialize(subdomain) self.subdomain = subdomain.sub(/\.$/, '') end |
Instance Attribute Details
#subdomain ⇒ Object
Returns the value of attribute subdomain.
2 3 4 |
# File 'lib/ensure_subdomain.rb', line 2 def subdomain @subdomain end |
Instance Method Details
#matches?(request) ⇒ Boolean
8 9 10 11 12 13 14 |
# File 'lib/ensure_subdomain.rb', line 8 def matches?(request) # don't deal with addresses like http://0.0.0.0:3000 request.domain.present? and # ''.match('www') #=> nil, which is is the opposite of what we want ((self.subdomain.empty? and request.subdomain.present?) or request.subdomain.match(self.subdomain).nil?) end |
#to(params, request) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/ensure_subdomain.rb', line 16 def to(params, request) url = request.protocol url << "#{self.subdomain}." if self.subdomain.present? url << "#{request.subdomain}." if vendor_url?(request) url << request.domain url << "/#{params[:path]}" if params[:path].present? url end |