From 798a14a6388ac525109e550d72bba0b1118e5e2e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 5 Mar 2015 13:11:53 -0800 Subject: pass a config to the route set This way we can get the relative_url_root from the application without setting another global value --- .../lib/action_dispatch/routing/route_set.rb | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 6d964c2cbf..0f3734dd74 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -20,8 +20,6 @@ module ActionDispatch # alias inspect to to_s. alias inspect to_s - mattr_accessor :relative_url_root - class Dispatcher < Routing::Endpoint def initialize(defaults) @defaults = defaults @@ -320,11 +318,25 @@ module ActionDispatch { :new => 'new', :edit => 'edit' } end - def initialize + def self.new_with_config(config) + if config.respond_to? :relative_url_root + new Config.new config.relative_url_root + else + # engines apparently don't have this set + new + end + end + + Config = Struct.new :relative_url_root + + DEFAULT_CONFIG = Config.new(nil) + + def initialize(config = DEFAULT_CONFIG) self.named_routes = NamedRouteCollection.new self.resources_path_names = self.class.default_resources_path_names self.default_url_options = {} + @config = config @append = [] @prepend = [] @disable_clear_and_finalize = false @@ -336,6 +348,10 @@ module ActionDispatch @formatter = Journey::Formatter.new @set end + def relative_url_root + @config.relative_url_root + end + def request_class ActionDispatch::Request end -- cgit v1.2.3