domain_routing 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/domain_routing/config.rb +21 -0
- data/lib/domain_routing/routing_additions.rb +81 -0
- data/lib/domain_routing/util.rb +17 -0
- data/lib/domain_routing.rb +3 -0
- metadata +65 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
module DomainRouting
|
2
|
+
class Config
|
3
|
+
class << self
|
4
|
+
def main_domains
|
5
|
+
@main_domains || []
|
6
|
+
end
|
7
|
+
|
8
|
+
def invalid_subdomains
|
9
|
+
@invalid_subdomains || []
|
10
|
+
end
|
11
|
+
|
12
|
+
def main_domains=(*values)
|
13
|
+
@main_domains = values.flatten
|
14
|
+
end
|
15
|
+
|
16
|
+
def invalid_subdomains=(*values)
|
17
|
+
@invalid_subdomains = values.flatten
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module DomainRouting
|
2
|
+
module RoutingAdditions
|
3
|
+
def with_domain
|
4
|
+
constraints DomainRouting::DomainConstraints do
|
5
|
+
yield
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def without_domain
|
10
|
+
constraints DomainRouting::Negated::DomainConstraints do
|
11
|
+
yield
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def with_subdomain
|
16
|
+
constraints DomainRouting::SubdomainConstraints do
|
17
|
+
yield
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def without_subdomain
|
22
|
+
constraints DomainRouting::Negated::SubdomainConstraints do
|
23
|
+
yield
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def with_domain_or_subdomain
|
28
|
+
constraints DomainRouting::DomainOrSubdomainConstraints do
|
29
|
+
yield
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def without_domain_or_subdomain
|
34
|
+
constraints DomainRouting::Negated::DomainOrSubdomainConstraints do
|
35
|
+
yield
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class DomainConstraints
|
41
|
+
def self.matches?(request)
|
42
|
+
DomainRouting::Util.domain_for(request).present?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class SubdomainConstraints
|
47
|
+
def self.matches?(request)
|
48
|
+
DomainRouting::Util.subdomain_for(request).present?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class DomainOrSubdomainConstraints
|
53
|
+
def self.matches?(request)
|
54
|
+
DomainRouting::DomainConstraints.matches?(request) || DomainRouting::SubdomainConstraints.matches?(request)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module Negated
|
59
|
+
class DomainConstraints
|
60
|
+
def self.matches?(request)
|
61
|
+
!DomainRouting::DomainConstraints.matches?(request)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class SubdomainConstraints
|
66
|
+
def self.matches?(request)
|
67
|
+
!DomainRouting::SubdomainConstraints.matches?(request)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class DomainOrSubdomainConstraints
|
72
|
+
def self.matches?(request)
|
73
|
+
!DomainRouting::DomainOrSubdomainConstraints.matches?(request)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class ActionDispatch::Routing::Mapper
|
80
|
+
include DomainRouting::RoutingAdditions
|
81
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module DomainRouting
|
2
|
+
class Util
|
3
|
+
class << self
|
4
|
+
def domain_for(request)
|
5
|
+
return "" if DomainRouting::Config.main_domains.include?(request.domain)
|
6
|
+
request.domain
|
7
|
+
end
|
8
|
+
|
9
|
+
def subdomain_for(request)
|
10
|
+
return "" unless request.subdomains.present?
|
11
|
+
subdomain = request.subdomains.last
|
12
|
+
return "" if DomainRouting::Config.invalid_subdomains.include?(subdomain)
|
13
|
+
subdomain
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: domain_routing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Mike Stone
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-07-26 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: A Rails 3 gem that allows easy routing using different domains and subdomains
|
22
|
+
email: stonemj@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/domain_routing.rb
|
31
|
+
- lib/domain_routing/config.rb
|
32
|
+
- lib/domain_routing/routing_additions.rb
|
33
|
+
- lib/domain_routing/util.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: https://github.com/mikestone/Domain-Routing
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
version: "0"
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.3.6
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Domain Routing
|
64
|
+
test_files: []
|
65
|
+
|