subdomainitis 0.9.3 → 0.9.21
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/lib/subdomainitis.rb +6 -57
- metadata +6 -6
data/lib/subdomainitis.rb
CHANGED
@@ -28,7 +28,7 @@ module Subdomainitis
|
|
28
28
|
|
29
29
|
|
30
30
|
class SubdomainRouteSet < ActionDispatch::Routing::RouteSet
|
31
|
-
|
31
|
+
def initialize(parent_route_set, subdomain_key)
|
32
32
|
@parent_route_set, @subdomain_key = parent_route_set, subdomain_key
|
33
33
|
super *[]
|
34
34
|
end
|
@@ -45,31 +45,7 @@ module Subdomainitis
|
|
45
45
|
[IsSubdomain.new(parent_route_set)],
|
46
46
|
request_class
|
47
47
|
)
|
48
|
-
|
49
48
|
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
class MainDomainRouteSet < ActionDispatch::Routing::RouteSet
|
54
|
-
|
55
|
-
def initialize(parent_route_set)
|
56
|
-
@parent_route_set = parent_route_set
|
57
|
-
super *[]
|
58
|
-
end
|
59
|
-
attr_reader :parent_route_set
|
60
|
-
|
61
|
-
def add_route(app, conditions = {}, requirements = {}, defaults = {}, name = nil, anchor = true)
|
62
|
-
parent_route_set.add_maindomain_route name
|
63
|
-
parent_route_set.add_route wrap(app), conditions, requirements, defaults, name, anchor
|
64
|
-
end
|
65
|
-
def wrap(app)
|
66
|
-
ActionDispatch::Routing::Mapper::Constraints.new(
|
67
|
-
app,
|
68
|
-
[IsMaindomain.new(parent_route_set)],
|
69
|
-
request_class
|
70
|
-
)
|
71
|
-
end
|
72
|
-
|
73
49
|
end
|
74
50
|
|
75
51
|
def subdomain_as(subdomain_key, &block)
|
@@ -79,9 +55,7 @@ module Subdomainitis
|
|
79
55
|
end
|
80
56
|
|
81
57
|
def main_domain(&block)
|
82
|
-
@set
|
83
|
-
maindomain_routeset = MainDomainRouteSet.new @set
|
84
|
-
maindomain_routeset.draw &block
|
58
|
+
constraints IsMaindomain.new(@set), &block
|
85
59
|
end
|
86
60
|
|
87
61
|
def use_fake_subdomains!
|
@@ -118,11 +92,8 @@ module Subdomainitis
|
|
118
92
|
|
119
93
|
module RouteSetMethods
|
120
94
|
def url_for_with_subdomains(args)
|
121
|
-
|
122
|
-
if subdomain_key = subdomain_routes[route_name]
|
95
|
+
if subdomain_key = subdomain_routes[args[:use_route]]
|
123
96
|
subdomain_url_for(subdomain_key, args.dup)
|
124
|
-
elsif maindomain_routes[route_name]
|
125
|
-
maindomain_url_for(args.dup)
|
126
97
|
else
|
127
98
|
url_for_without_subdomains args
|
128
99
|
end
|
@@ -140,42 +111,20 @@ module Subdomainitis
|
|
140
111
|
end)
|
141
112
|
end
|
142
113
|
|
143
|
-
def maindomain_url_for(args)
|
144
|
-
raise HostRequired.new if args[:only_path]
|
145
|
-
|
146
|
-
url_for_without_subdomains(if use_fake_subdomains
|
147
|
-
args
|
148
|
-
else
|
149
|
-
args.merge :host => main_domain_host(args[:host])
|
150
|
-
end)
|
151
|
-
end
|
152
|
-
|
153
114
|
def add_subdomain_route(name, subdomain_key)
|
154
115
|
subdomain_routes[name] = subdomain_key
|
155
116
|
end
|
156
117
|
|
157
|
-
def add_maindomain_route(name)
|
158
|
-
maindomain_routes[name] = true
|
159
|
-
end
|
160
|
-
|
161
118
|
def host_name(subdomain_parameter, host)
|
162
119
|
raise HostRequired.new unless host
|
163
|
-
|
120
|
+
index = -1 - tld_length
|
164
121
|
subdomain_parameter = if subdomain_parameter.respond_to?(:to_param)
|
165
122
|
subdomain_parameter.to_param
|
166
123
|
else
|
167
124
|
subdomain_parameter
|
168
125
|
end
|
169
126
|
|
170
|
-
([subdomain_parameter] + host.split(".")[
|
171
|
-
end
|
172
|
-
|
173
|
-
def main_domain_host(host)
|
174
|
-
host.split(".")[subdomain_index..-1].join(".")
|
175
|
-
end
|
176
|
-
|
177
|
-
def subdomain_index
|
178
|
-
-1 - tld_length
|
127
|
+
([subdomain_parameter] + host.split(".")[index..-1]).join(".")
|
179
128
|
end
|
180
129
|
|
181
130
|
end
|
@@ -184,7 +133,7 @@ module Subdomainitis
|
|
184
133
|
mapper.instance_variable_get(:@set).class_eval do
|
185
134
|
include RouteSetMethods
|
186
135
|
alias_method_chain :url_for, :subdomains
|
187
|
-
attr_accessor :subdomain_routes, :
|
136
|
+
attr_accessor :subdomain_routes, :use_fake_subdomains, :tld_length
|
188
137
|
end
|
189
138
|
|
190
139
|
delegate :tld_length=, :to => :@set
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 21
|
9
|
+
version: 0.9.21
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Stephen Judkins
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2010-10-25 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -36,13 +36,13 @@ dependencies:
|
|
36
36
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
37
|
none: false
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - "="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
segments:
|
42
42
|
- 3
|
43
43
|
- 0
|
44
|
-
-
|
45
|
-
version: 3.0.
|
44
|
+
- 1
|
45
|
+
version: 3.0.1
|
46
46
|
type: :runtime
|
47
47
|
version_requirements: *id002
|
48
48
|
description: subdomainitis provides easy, simple support for using wildcard subdomains as controller parameters in Rails 3
|