lib/subdomain-fu.rb in pboling-subdomain-fu-0.5.3 vs lib/subdomain-fu.rb in pboling-subdomain-fu-0.6.0

- old
+ new

@@ -31,10 +31,14 @@ # Sets the TLD Size of the current environment def self.tld_size=(value) tld_sizes[RAILS_ENV.to_sym] = value end + def self.has_domain?(host) + !host.blank? && !(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(host)) + end + # Is the current subdomain either nil or not a mirror? def self.has_subdomain?(subdomain) subdomain != false && !subdomain.blank? && !SubdomainFu.mirrors.include?(subdomain) end @@ -47,11 +51,11 @@ subdomain == SubdomainFu.preferred_mirror || SubdomainFu.preferred_mirror.nil? end # Gets the subdomain from the host based on the TLD size def self.subdomain_from(host) - return nil if host.nil? || /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(host) + return nil unless has_domain?(host) parts = host.split('.') sub = parts[0..-(SubdomainFu.tld_size+2)].join(".") sub.blank? ? nil : sub end @@ -126,20 +130,23 @@ def self.crazy_rewrite_rule(subdomain, host) (!has_subdomain?(subdomain) && preferred_mirror?(subdomain) && !preferred_mirror?(subdomain_from(host))) || !same_subdomain?(subdomain, host) end + #returns nil or the subdomain(s) def self.current_subdomain(request) subdomain = request.subdomains(SubdomainFu.tld_size).join(".") if has_subdomain?(subdomain) subdomain else nil end end + #returns nil or the domain or ip #Enables subdomain-fu to more completely replace DHH's account_location plugin def self.current_domain(request) + return request.domain unless has_domain?(request.domain) domain = "" domain << request.subdomains[1..-1].join(".") + "." if request.subdomains.length > 1 domain << request.domain + request.port_string end