pboling-subdomain-fu 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +6 -0
- data/VERSION.yml +2 -2
- data/lib/subdomain-fu.rb +8 -1
- data/spec/subdomain_fu_spec.rb +26 -0
- metadata +1 -1
data/CHANGELOG
CHANGED
data/VERSION.yml
CHANGED
data/lib/subdomain-fu.rb
CHANGED
@@ -33,6 +33,10 @@ module SubdomainFu
|
|
33
33
|
tld_sizes[RAILS_ENV.to_sym] = value
|
34
34
|
end
|
35
35
|
|
36
|
+
def self.has_domain?(host)
|
37
|
+
!host.blank? && !(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(host))
|
38
|
+
end
|
39
|
+
|
36
40
|
# Is the current subdomain either nil or not a mirror?
|
37
41
|
def self.has_subdomain?(subdomain)
|
38
42
|
subdomain != false && !subdomain.blank? && !SubdomainFu.mirrors.include?(subdomain)
|
@@ -49,7 +53,7 @@ module SubdomainFu
|
|
49
53
|
|
50
54
|
# Gets the subdomain from the host based on the TLD size
|
51
55
|
def self.subdomain_from(host)
|
52
|
-
return nil
|
56
|
+
return nil unless has_domain?(host)
|
53
57
|
parts = host.split('.')
|
54
58
|
sub = parts[0..-(SubdomainFu.tld_size+2)].join(".")
|
55
59
|
sub.blank? ? nil : sub
|
@@ -128,6 +132,7 @@ module SubdomainFu
|
|
128
132
|
!same_subdomain?(subdomain, host)
|
129
133
|
end
|
130
134
|
|
135
|
+
#returns nil or the subdomain(s)
|
131
136
|
def self.current_subdomain(request)
|
132
137
|
subdomain = request.subdomains(SubdomainFu.tld_size).join(".")
|
133
138
|
if has_subdomain?(subdomain)
|
@@ -137,8 +142,10 @@ module SubdomainFu
|
|
137
142
|
end
|
138
143
|
end
|
139
144
|
|
145
|
+
#returns nil or the domain or ip
|
140
146
|
#Enables subdomain-fu to more completely replace DHH's account_location plugin
|
141
147
|
def self.current_domain(request)
|
148
|
+
return request.domain unless has_domain?(request.domain)
|
142
149
|
domain = ""
|
143
150
|
domain << request.subdomains[1..-1].join(".") + "." if request.subdomains.length > 1
|
144
151
|
domain << request.domain + request.port_string
|
data/spec/subdomain_fu_spec.rb
CHANGED
@@ -31,6 +31,32 @@ describe "SubdomainFu" do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
describe "#has_domain?" do
|
35
|
+
it "should be true for domains with tld" do
|
36
|
+
SubdomainFu.has_domain?("my.example.com").should be_true
|
37
|
+
SubdomainFu.has_domain?("bonkers.example.net").should be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be false for IP addresses" do
|
41
|
+
SubdomainFu.has_domain?("192.168.100.252").should be_false
|
42
|
+
SubdomainFu.has_domain?("127.0.0.1").should be_false
|
43
|
+
SubdomainFu.has_domain?("4.2.2.2").should be_false
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should be true for localhost" do
|
47
|
+
SubdomainFu.has_domain?("localhost:3000").should be_true
|
48
|
+
SubdomainFu.has_domain?("www.localhost").should be_true
|
49
|
+
SubdomainFu.has_domain?("www.localhost:3000").should be_true
|
50
|
+
SubdomainFu.has_domain?("localhost").should be_true
|
51
|
+
end
|
52
|
+
|
53
|
+
it "shoud be false for a nil or blank subdomain" do
|
54
|
+
SubdomainFu.has_domain?("").should be_false
|
55
|
+
SubdomainFu.has_domain?(nil).should be_false
|
56
|
+
SubdomainFu.has_domain?(false).should be_false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
34
60
|
describe "#has_subdomain?" do
|
35
61
|
it "should be true for non-mirrored subdomains" do
|
36
62
|
SubdomainFu.has_subdomain?("awesome").should be_true
|