domain_routing 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,8 @@
1
1
  module DomainRouting
2
2
  class Config
3
3
  class << self
4
+ attr_accessor :act_as_ssl
5
+
4
6
  def main_domains
5
7
  @main_domains || []
6
8
  end
@@ -35,6 +35,30 @@ module DomainRouting
35
35
  yield
36
36
  end
37
37
  end
38
+
39
+ def with_ssl
40
+ constraints DomainRouting::SSL do
41
+ yield
42
+ end
43
+ end
44
+
45
+ def without_ssl
46
+ constraints DomainRouting::Negated::SSL do
47
+ yield
48
+ end
49
+ end
50
+
51
+ def secure_redirect(route)
52
+ ssl = redirect do |_, request|
53
+ "https://#{request.host_with_port}#{request.fullpath}"
54
+ end
55
+
56
+ if route == :root
57
+ root :to => ssl
58
+ else
59
+ match route, :to => ssl
60
+ end
61
+ end
38
62
  end
39
63
 
40
64
  class DomainConstraints
@@ -55,6 +79,13 @@ module DomainRouting
55
79
  end
56
80
  end
57
81
 
82
+ class SSL
83
+ def self.matches?(request)
84
+ return true if DomainRouting::Config.act_as_ssl
85
+ request.ssl?
86
+ end
87
+ end
88
+
58
89
  module Negated
59
90
  class DomainConstraints
60
91
  def self.matches?(request)
@@ -73,6 +104,12 @@ module DomainRouting
73
104
  !DomainRouting::DomainOrSubdomainConstraints.matches?(request)
74
105
  end
75
106
  end
107
+
108
+ class SSL
109
+ def self.matches?(request)
110
+ !DomainRouting::SSL.matches?(request)
111
+ end
112
+ end
76
113
  end
77
114
  end
78
115
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domain_routing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
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: 2011-08-22 00:00:00.000000000Z
12
+ date: 2011-08-23 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: A Rails 3 gem that allows easy routing using different domains and subdomains
15
15
  email: stonemj@gmail.com