rails_reroute 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -5,3 +5,7 @@ class AirTrafficController < ApplicationController
5
5
  reroute "status"
6
6
  end
7
7
  end
8
+
9
+ You can add it to your project by adding this to your Gemfile
10
+
11
+ gem 'rails_reroute', :require => 'rails_reroute'
data/lib/rails_reroute.rb CHANGED
@@ -3,24 +3,32 @@ module RailsReroute
3
3
  initializer "rails_reroute.initializer" do
4
4
  ActionController::Base.class_eval do
5
5
  def reroute new_route
6
- new_paths = {"PATH_INFO" => "#{new_route}", "REQUEST_URI"=>"#{env["rack.url_scheme"]}://#{env["HTTP_HOST"]}#{new_route}", "REQUEST_PATH"=>"#{new_route}"}
7
- env.keys.each_with_index do |key,idx|
8
- env.delete(key) if idx > 29
9
- end
10
- env.merge! new_paths
6
+ new_env = reroute_new_env new_route
11
7
  unlock_request
12
- Rails.application.call(env)
13
- @_response = env["action_controller.instance"].response
8
+ Rails.application.call(new_env)
9
+ @_response = new_env["action_controller.instance"].response
14
10
  @_response_body = @_response.body
15
11
  end
16
12
 
13
+ def reroute_default_variables
14
+ %w( CONTENT_TYPE CONTENT_LENGTH
15
+ HTTPS AUTH_TYPE GATEWAY_INTERFACE
16
+ PATH_INFO PATH_TRANSLATED QUERY_STRING
17
+ REMOTE_ADDR REMOTE_HOST REMOTE_IDENT REMOTE_USER
18
+ REQUEST_METHOD SCRIPT_NAME
19
+ SERVER_NAME SERVER_PORT SERVER_PROTOCOL SERVER_SOFTWARE )
20
+ end
21
+
22
+ def reroute_new_env new_route
23
+ new_env = env.clone
24
+ new_paths = {"PATH_INFO" => "#{new_route}", "REQUEST_URI"=>"#{env["rack.url_scheme"]}://#{env["HTTP_HOST"]}#{new_route}", "REQUEST_PATH"=>"#{new_route}"}
25
+ reroute_default_variables.each { |key| new_env[key] = env[key] }
26
+ new_env.merge new_paths
27
+ end
28
+
17
29
  def unlock_request
18
- Rails.application.app.instance_eval do
19
- if @app.kind_of? Rack::Lock
20
- @app.instance_eval do
21
- @mutex.unlock
22
- end
23
- end
30
+ unless Rails.application.config.allow_concurrency
31
+ Rack::Lock.new(Rails.application).call(env) rescue ThreadError
24
32
  end
25
33
  end
26
34
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "rails_reroute"
3
- s.version = "0.1"
3
+ s.version = "0.2"
4
4
 
5
5
  s.authors = ["Nathaniel Barnes"]
6
6
  s.email = ["Nathaniel.R.Barnes@gmail.com"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_reroute
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
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-03-04 00:00:00.000000000 Z
12
+ date: 2013-03-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Reroute rails requests fully
15
15
  email:
@@ -37,18 +37,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
37
37
  - - ! '>='
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
- segments:
41
- - 0
42
- hash: -2367698615116766147
43
40
  required_rubygems_version: !ruby/object:Gem::Requirement
44
41
  none: false
45
42
  requirements:
46
43
  - - ! '>='
47
44
  - !ruby/object:Gem::Version
48
45
  version: '0'
49
- segments:
50
- - 0
51
- hash: -2367698615116766147
52
46
  requirements: []
53
47
  rubyforge_project: rails_reroute
54
48
  rubygems_version: 1.8.24
@@ -56,3 +50,4 @@ signing_key:
56
50
  specification_version: 3
57
51
  summary: Reroute rails requests fully
58
52
  test_files: []
53
+ has_rdoc: