aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/rack
diff options
context:
space:
mode:
authorRyan Bigg <radarlistener@gmail.com>2009-04-04 16:13:18 +1000
committerRyan Bigg <radarlistener@gmail.com>2009-04-04 16:13:18 +1000
commite878c3e44a8dba19c1188b636e25ec1bc2165116 (patch)
tree3d06b83492653b6b73422cbf37014fc5c89e9685 /railties/lib/rails/rack
parentab55ddcc4c5cf31bcaf7720b52dc55d6d54cb150 (diff)
parent9e9469e83f6144310115124cdecc5cb65db5128e (diff)
downloadrails-e878c3e44a8dba19c1188b636e25ec1bc2165116.tar.gz
rails-e878c3e44a8dba19c1188b636e25ec1bc2165116.tar.bz2
rails-e878c3e44a8dba19c1188b636e25ec1bc2165116.zip
Merge branch 'master' of git@github.com:lifo/docrails
* 'master' of git@github.com:lifo/docrails: (319 commits) deletes screencast promo in prologue, its proper place is the References section Typo fix list -> index in caching guide, RESTifies some examples, revised conventions here and there Tech edit of caching guide from Gregg Pollack Fix typo in comment: hide_actions -> hide_action Fix two typos in a comment in config/initializers/backtrace_silencers.rb With -> with in a title Clear up a little confusing wording in Routing Guide. copyedited minor details in the rack on rails guide remove piece of UrlWriter documentation claiming that you can access named routes as its class methods Add note about change to session options TRUNCATE is also a MySQL DDL statement, so document this is a possible caveat when using transactions and savepoints. Improve documentation for ActiveResource::Validations, fix typos Fix typos in ActiveResource::Base documentation, use present tense, reword confusing sentences Update ActiveResource::Connection documentation to use present tense Fix typos in Active Resource README Fix a small typo ensure authors get warnings about broken links, and ensure end users don't in guides generator, warn about duplicate header IDs only if WARN_DUPLICATE_HEADERS ...
Diffstat (limited to 'railties/lib/rails/rack')
-rw-r--r--railties/lib/rails/rack/metal.rb27
-rw-r--r--railties/lib/rails/rack/static.rb17
2 files changed, 34 insertions, 10 deletions
diff --git a/railties/lib/rails/rack/metal.rb b/railties/lib/rails/rack/metal.rb
index b185227234..adc43da864 100644
--- a/railties/lib/rails/rack/metal.rb
+++ b/railties/lib/rails/rack/metal.rb
@@ -6,15 +6,30 @@ module Rails
NotFoundResponse = [404, {}, []].freeze
NotFound = lambda { NotFoundResponse }
+ cattr_accessor :metal_paths
+ self.metal_paths = ["#{Rails.root}/app/metal"]
+ cattr_accessor :requested_metals
+
def self.metals
- base = "#{Rails.root}/app/metal"
- matcher = /\A#{Regexp.escape(base)}\/(.*)\.rb\Z/
+ matcher = /#{Regexp.escape('/app/metal/')}(.*)\.rb\Z/
+ metal_glob = metal_paths.map{ |base| "#{base}/**/*.rb" }
+ all_metals = {}
- Dir["#{base}/**/*.rb"].sort.map do |file|
- file.sub!(matcher, '\1')
- require file
- file.classify.constantize
+ metal_glob.each do |glob|
+ Dir[glob].sort.map do |file|
+ file = file.match(matcher)[1]
+ all_metals[file.camelize] = file
+ end
end
+
+ load_list = requested_metals || all_metals.keys
+
+ load_list.map do |requested_metal|
+ if metal = all_metals[requested_metal]
+ require metal
+ requested_metal.constantize
+ end
+ end.compact
end
def initialize(app)
diff --git a/railties/lib/rails/rack/static.rb b/railties/lib/rails/rack/static.rb
index ef4e2642e2..f07c6beb5e 100644
--- a/railties/lib/rails/rack/static.rb
+++ b/railties/lib/rails/rack/static.rb
@@ -13,14 +13,18 @@ module Rails
def call(env)
path = env['PATH_INFO'].chomp('/')
method = env['REQUEST_METHOD']
- cached_path = (path.empty? ? 'index' : path) + ::ActionController::Base.page_cache_extension
if FILE_METHODS.include?(method)
if file_exist?(path)
return @file_server.call(env)
- elsif file_exist?(cached_path)
- env['PATH_INFO'] = cached_path
- return @file_server.call(env)
+ else
+ cached_path = directory_exist?(path) ? "#{path}/index" : path
+ cached_path += ::ActionController::Base.page_cache_extension
+
+ if file_exist?(cached_path)
+ env['PATH_INFO'] = cached_path
+ return @file_server.call(env)
+ end
end
end
@@ -32,6 +36,11 @@ module Rails
full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path))
File.file?(full_path) && File.readable?(full_path)
end
+
+ def directory_exist?(path)
+ full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path))
+ File.directory?(full_path) && File.readable?(full_path)
+ end
end
end
end