ensure_subdomain 0.0.3 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ensure_subdomain/version.rb +3 -3
- data/lib/ensure_subdomain.rb +21 -34
- metadata +2 -3
- data/ensure_subdomain-0.0.2.gem +0 -0
data/lib/ensure_subdomain.rb
CHANGED
@@ -1,51 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
class EnsureSubdomain
|
2
|
+
attr_accessor :subdomain
|
3
|
+
|
4
|
+
def initialize(subdomain)
|
5
|
+
self.subdomain = subdomain.sub(/\.$/, '')
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
request.subdomain =~ /^.*$/
|
11
|
-
end
|
8
|
+
def matches?(request)
|
9
|
+
request.subdomain.match(self.subdomain).nil?
|
12
10
|
end
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def matches?(request)
|
22
|
-
request.subdomain.match(self.pattern).nil?
|
23
|
-
end
|
11
|
+
|
12
|
+
def to(params, request)
|
13
|
+
url = request.protocol
|
14
|
+
url << "#{self.subdomain}." if self.subdomain.present?
|
15
|
+
url << request.domain
|
16
|
+
url << "/#{params[:path]}" if params[:path].present?
|
17
|
+
url
|
24
18
|
end
|
25
19
|
end
|
26
20
|
|
27
21
|
module ActionDispatch::Routing::Mapper::HttpHelpers
|
28
|
-
include EnsureSubdomain
|
29
|
-
|
30
22
|
def ensure_no_www
|
31
|
-
|
32
|
-
get '/', to: redirect { |params, request| "#{request.protocol}#{request.domain}" }
|
33
|
-
match '/*path', to: redirect { |params, request| "#{request.protocol}#{request.domain}/#{params[:path]}" }, via: [:get, :post, :put, :patch, :delete]
|
34
|
-
end
|
23
|
+
ensure_subdomain ''
|
35
24
|
end
|
36
25
|
alias_method :ensure_non_www, :ensure_no_www
|
37
26
|
|
38
27
|
def ensure_www
|
39
|
-
|
40
|
-
get '/', to: redirect { |params, request| "#{request.protocol}www.#{request.domain}" }
|
41
|
-
match '/*path', to: redirect { |params, request| "#{request.protocol}www.#{request.domain}/#{params[:path]}" }, via: [:get, :post, :put, :patch, :delete]
|
42
|
-
end
|
28
|
+
ensure_subdomain 'www'
|
43
29
|
end
|
44
30
|
|
45
|
-
def ensure_subdomain(
|
46
|
-
|
47
|
-
|
48
|
-
|
31
|
+
def ensure_subdomain(subdomain, options={})
|
32
|
+
redirector = EnsureSubdomain.new( subdomain )
|
33
|
+
verbs = options[:via] || [:get, :post, :put, :patch, :delete]
|
34
|
+
constraints( redirector ) do
|
35
|
+
match '/*path', to: redirect { |params, request| redirector.to params, request }, via: verbs
|
49
36
|
end
|
50
37
|
end
|
51
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ensure_subdomain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -37,7 +37,6 @@ extra_rdoc_files: []
|
|
37
37
|
files:
|
38
38
|
- LICENSE
|
39
39
|
- README.md
|
40
|
-
- ensure_subdomain-0.0.2.gem
|
41
40
|
- ensure_subdomain.gemspec
|
42
41
|
- lib/ensure_subdomain.rb
|
43
42
|
- lib/ensure_subdomain/version.rb
|
data/ensure_subdomain-0.0.2.gem
DELETED
Binary file
|