aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-03-02 11:01:07 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2015-03-02 11:01:07 -0800
commit37654d12ae95f751a91167a68bfb8d1bfd168d9c (patch)
treea02bba3f074f7eba21ceaa61873098fa4e2525bb /actionpack/lib/action_dispatch
parenta8a361cf80e145973ca5b19551a206f933d60c60 (diff)
downloadrails-37654d12ae95f751a91167a68bfb8d1bfd168d9c.tar.gz
rails-37654d12ae95f751a91167a68bfb8d1bfd168d9c.tar.bz2
rails-37654d12ae95f751a91167a68bfb8d1bfd168d9c.zip
ask the routes objects for its Rack env key
this centralizes the logic for determining the script name key and drops object allocations when calling `engine_script_name` (which is called on each `url_for`).
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/http/request.rb2
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb2
2 files changed, 3 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb
index 07b3814ca4..732ee67268 100644
--- a/actionpack/lib/action_dispatch/http/request.rb
+++ b/actionpack/lib/action_dispatch/http/request.rb
@@ -114,7 +114,7 @@ module ActionDispatch
end
def engine_script_name(_routes) # :nodoc:
- env["ROUTES_#{_routes.object_id}_SCRIPT_NAME"]
+ env[_routes.env_key]
end
def request_method=(request_method) #:nodoc:
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index ce04f0b08a..7eb61af770 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -308,6 +308,7 @@ module ActionDispatch
attr_accessor :formatter, :set, :named_routes, :default_scope, :router
attr_accessor :disable_clear_and_finalize, :resources_path_names
attr_accessor :default_url_options, :request_class
+ attr_reader :env_key
alias :routes :set
@@ -325,6 +326,7 @@ module ActionDispatch
@prepend = []
@disable_clear_and_finalize = false
@finalized = false
+ @env_key = "ROUTES_#{object_id}_SCRIPT_NAME".freeze
@set = Journey::Routes.new
@router = Journey::Router.new @set