Class: Ress::Subdomain::RegexpSubdomain

Inherits:
Object
  • Object
show all
Defined in:
lib/ress/subdomain.rb

Overview

The main inspiration for this class is to match xip.io subdomains for many devs working in development mode with the same configuration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subdomain) ⇒ RegexpSubdomain

Returns a new instance of RegexpSubdomain.



56
57
58
# File 'lib/ress/subdomain.rb', line 56

def initialize(subdomain)
  @subdomain = subdomain
end

Instance Attribute Details

#subdomainObject (readonly)

Returns the value of attribute subdomain.



54
55
56
# File 'lib/ress/subdomain.rb', line 54

def subdomain
  @subdomain
end

Instance Method Details

#matches?(subdomain) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/ress/subdomain.rb', line 60

def matches?(subdomain)
  self.subdomain =~ subdomain
end

#url(protocol, fullpath, subdomain) ⇒ Object



64
65
66
67
68
69
# File 'lib/ress/subdomain.rb', line 64

def url(protocol, fullpath, subdomain)
  fullpath = fullpath[(subdomain.length + 1)..-1] unless subdomain.empty?
  begin
    return build_url(protocol, subdomain, fullpath) if matches?(subdomain)
  end while( subdomain.slice!(/^[^\.]+\.?/) )
end