aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorSimon Jefford <simon.jefford@gmail.com>2010-07-27 15:39:28 +0100
committerwycats <wycats@gmail.com>2010-09-09 18:26:35 -0700
commit7fae0aa4ac116bcbf522a9a4f19972c653d366fa (patch)
treebd10694c9fad90d35b44150168c3d1df03bbb6b2 /actionpack/lib
parent5949e705f496c78fa125610d581a9339fa63da94 (diff)
downloadrails-7fae0aa4ac116bcbf522a9a4f19972c653d366fa.tar.gz
rails-7fae0aa4ac116bcbf522a9a4f19972c653d366fa.tar.bz2
rails-7fae0aa4ac116bcbf522a9a4f19972c653d366fa.zip
Add configuration option for tld length
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/http/url.rb10
-rw-r--r--actionpack/lib/action_dispatch/railtie.rb10
2 files changed, 16 insertions, 4 deletions
diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb
index 38f46fa120..2e39d0dbc2 100644
--- a/actionpack/lib/action_dispatch/http/url.rb
+++ b/actionpack/lib/action_dispatch/http/url.rb
@@ -1,7 +1,9 @@
module ActionDispatch
module Http
module URL
- # Returns the complete \URL used for this request.
+ mattr_accessor :tld_length
+
+ # Returns the complete URL used for this request.
def url
protocol + host_with_port + fullpath
end
@@ -85,13 +87,13 @@ module ActionDispatch
# returned for "dev.www.rubyonrails.org". You can specify a different <tt>tld_length</tt>,
# such as 2 to catch <tt>["www"]</tt> instead of <tt>["www", "rubyonrails"]</tt>
# in "www.rubyonrails.co.uk".
- def subdomains(tld_length = 1)
+ def subdomains(tld_length = @@tld_length)
return [] unless named_host?(host)
parts = host.split('.')
parts[0..-(tld_length+2)]
end
- def subdomain(tld_length = 1)
+ def subdomain(tld_length = @@tld_length)
subdomains(tld_length).join('.')
end
@@ -102,4 +104,4 @@ module ActionDispatch
end
end
end
-end
+end \ No newline at end of file
diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb
index ed066ad75e..c202fee990 100644
--- a/actionpack/lib/action_dispatch/railtie.rb
+++ b/actionpack/lib/action_dispatch/railtie.rb
@@ -8,5 +8,15 @@ module ActionDispatch
config.action_dispatch.ip_spoofing_check = true
config.action_dispatch.show_exceptions = true
config.action_dispatch.best_standards_support = true
+ config.action_dispatch.tld_length = 1
+
+ # Prepare dispatcher callbacks and run 'prepare' callbacks
+ initializer "action_dispatch.prepare_dispatcher" do |app|
+ ActionDispatch::Callbacks.to_prepare { app.routes_reloader.execute_if_updated }
+ end
+
+ initializer "action_dispatch.configure" do |app|
+ ActionDispatch::Http::URL.tld_length = app.config.action_dispatch.tld_length
+ end
end
end