ssl_routes 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,6 @@ module SslRoutes
4
4
 
5
5
  def self.included(base)
6
6
  base.extend ClassMethods
7
- base.send :include, InstanceMethods
8
7
  end
9
8
 
10
9
  module ClassMethods
@@ -20,63 +19,54 @@ module SslRoutes
20
19
 
21
20
  end
22
21
 
23
- module InstanceMethods
24
-
25
- def determine_protocols(options)
26
- current = self.request.ssl? ? 'https' : 'http'
27
- target = case options[self.parameter]
28
- when String then options[self.parameter]
29
- when TrueClass then 'https'
30
- else 'http'
31
- end
32
- target = current if [:all, :both].include? options[self.parameter]
33
- target = 'https' if self.secure_session && current_user
34
- target = options[:protocol] if options[:protocol]
35
- [ current, target.split(':').first ]
22
+ def determine_protocols(options)
23
+ current = self.request.ssl? ? 'https' : 'http'
24
+ target = case options[self.parameter]
25
+ when String then options[self.parameter]
26
+ when TrueClass then 'https'
27
+ else 'http'
36
28
  end
29
+ target = current if [:all, :both].include? options[self.parameter]
30
+ target = 'https' if self.secure_session && current_user
31
+ target = options[:protocol] if options[:protocol]
32
+ [ current, target.split(':').first ]
33
+ end
37
34
 
38
- private
35
+ private
39
36
 
40
- def ensure_protocol
41
- routes = Rails.application.routes
42
- options = routes.recognize_path request.path, {:method => request.env['REQUEST_METHOD']}
43
- current, target = determine_protocols(options)
44
- if current != target && !request.xhr? && request.get?
45
- flash.keep
46
- redirect_to URI.join("#{target}://#{request.host_with_port}", request.fullpath).to_s
47
- return false
48
- end
37
+ def ensure_protocol
38
+ routes = Rails.application.routes
39
+ options = routes.recognize_path request.path, {:method => request.env['REQUEST_METHOD']}
40
+ current, target = determine_protocols(options)
41
+ if current != target && !request.xhr? && request.get?
42
+ flash.keep
43
+ redirect_to URI.join("#{target}://#{request.host_with_port}", request.fullpath).to_s
44
+ return false
49
45
  end
50
-
51
- end
46
+ end
52
47
 
53
48
  end
54
49
 
55
50
  module ActionDispatch
56
51
 
57
52
  def self.included(base)
58
- base.send :include, InstanceMethods
59
53
  base.send :alias_method_chain, :url_for, :ssl_support
60
54
  end
61
55
 
62
- module InstanceMethods
63
-
64
- def url_for_with_ssl_support(options)
65
- if options.is_a?(Hash) && options[:only_path] == true
66
- ac = self.respond_to?(:controller) ? self.controller : self
67
- if ac.respond_to?(:enable_ssl) && ac.enable_ssl
68
- case options
69
- when Hash
70
- current, target = ac.determine_protocols(options)
71
- if current != target
72
- options.merge!({ :protocol => target, :only_path => false })
73
- end
74
- end
56
+ def url_for_with_ssl_support(options)
57
+ if options.is_a?(Hash) && options[:only_path] == true
58
+ ac = self.respond_to?(:controller) ? self.controller : self
59
+ if ac.respond_to?(:enable_ssl) && ac.enable_ssl
60
+ case options
61
+ when Hash
62
+ current, target = ac.determine_protocols(options)
63
+ if current != target
64
+ options.merge!({ :protocol => target, :only_path => false })
65
+ end
75
66
  end
76
67
  end
77
- url_for_without_ssl_support(options)
78
68
  end
79
-
69
+ url_for_without_ssl_support(options)
80
70
  end
81
71
 
82
72
  end
@@ -1,5 +1,5 @@
1
1
  module SslRoutes
2
2
 
3
- VERSION = '0.1.4'
3
+ VERSION = '0.1.5'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ssl_routes
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Cedric Howe
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-29 00:00:00 Z
18
+ date: 2012-07-12 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rails