Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
detect dispatch.cgi correctly, and search constants smartly.
Browse files Browse the repository at this point in the history
Thanks, Andre Nathan.
  • Loading branch information
shugo committed Jan 23, 2007
1 parent ee531e8 commit a889e99
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions lib/apache/rails-dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def translate_uri(r)
end

def handler(r)
if !/\Adispatch\.(cgi|fcgi|rb)\z/.match(r.filename) &&
if !/\Adispatch\.(cgi|fcgi|rb)\z/.match(File.basename(r.filename)) &&
File.file?(r.filename)
return DECLINED
end
Expand Down Expand Up @@ -419,6 +419,19 @@ def name
return name__.sub(/\AApache::RailsDispatcher::CURRENT_MODULE::/, "")
end

def as_load_path
if self == Object || self == Kernel ||
self == Apache::RailsDispatcher::CURRENT_MODULE
''
elsif is_a? Class
parent == self ? '' : parent.as_load_path
else
name.split('::').collect do |word|
word.underscore
end * '/'
end
end

def const_missing(class_id)
env = Apache::RailsDispatcher.current_environment
unless env
Expand All @@ -431,12 +444,18 @@ def const_missing(class_id)
file_name = class_id.to_s.demodulize.underscore
file_path = as_load_path.empty? ? file_name : "#{as_load_path}/#{file_name}"
require_dependency(file_path)
if env.module.const_defined?(class_id)
return env.module.const_get(class_id)
if const_defined?(class_id)
return const_get(class_id)
else
raise LoadError
end
rescue LoadError => e
# Look for a directory in the load path that we ought to load.
if $LOAD_PATH.any? { |base| File.directory? "#{base}/#{file_path}" }
mod = Module.new
env.module.const_set class_id, mod
return env.module.const_get(class_id)
end
raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e)
end
end
Expand Down

0 comments on commit a889e99

Please sign in to comment.