diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-03-04 11:02:24 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-03-04 11:02:24 -0800 |
commit | c2108926a4638b5373f846c2d6165bf28108b9cb (patch) | |
tree | c953bb2bfc56aa0b3453e7a6d6a8febc49e89dba | |
parent | 154d60c8ce6863c6466de22efceccb6f104a89ae (diff) | |
download | rails-c2108926a4638b5373f846c2d6165bf28108b9cb.tar.gz rails-c2108926a4638b5373f846c2d6165bf28108b9cb.tar.bz2 rails-c2108926a4638b5373f846c2d6165bf28108b9cb.zip |
Drop request class from RouteSet constructor.
If you would like to use a custom request class, please subclass and implemet
the `request_class` method.
-rw-r--r-- | actionpack/CHANGELOG.md | 7 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 11 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 6 |
3 files changed, 19 insertions, 5 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 3343a92bf7..108ebfda58 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,10 @@ +* Drop request class from RouteSet constructor. + + If you would like to use a custom request class, please subclass and implemet + the `request_class` method. + + *tenderlove@ruby-lang.org* + * Fallback to `ENV['RAILS_RELATIVE_URL_ROOT']` in `url_for`. Fixed an issue where the `RAILS_RELATIVE_URL_ROOT` environment variable is not diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 29853a3474..6d964c2cbf 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -311,7 +311,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_accessor :default_url_options attr_reader :env_key alias :routes :set @@ -320,11 +320,10 @@ module ActionDispatch { :new => 'new', :edit => 'edit' } end - def initialize(request_class = ActionDispatch::Request) + def initialize self.named_routes = NamedRouteCollection.new self.resources_path_names = self.class.default_resources_path_names self.default_url_options = {} - self.request_class = request_class @append = [] @prepend = [] @@ -337,6 +336,10 @@ module ActionDispatch @formatter = Journey::Formatter.new @set end + def request_class + ActionDispatch::Request + end + def draw(&block) clear! unless @disable_clear_and_finalize eval_block(block) @@ -545,7 +548,7 @@ module ActionDispatch conditions.keep_if do |k, _| k == :action || k == :controller || k == :required_defaults || - @request_class.public_method_defined?(k) || path_values.include?(k) + request_class.public_method_defined?(k) || path_values.include?(k) end end private :build_conditions diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index b4502c19d6..55fc160ac8 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -3583,7 +3583,11 @@ class TestAltApp < ActionDispatch::IntegrationTest end end - AltRoutes = ActionDispatch::Routing::RouteSet.new(AltRequest) + AltRoutes = Class.new(ActionDispatch::Routing::RouteSet) { + def request_class + AltRequest + end + }.new AltRoutes.draw do get "/" => TestAltApp::XHeader.new, :constraints => {:x_header => /HEADER/} get "/" => TestAltApp::AltApp.new |