aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2009-09-12 15:38:34 -0500
committerYehuda Katz <wycats@gmail.com>2009-09-12 15:38:34 -0500
commit76cd4cb27e2ec197c7f62082334d5d7211fd2d19 (patch)
tree80b0e0a843ae3d88a0b2ae0da7769379d0624f69
parentddb4600ce608b14f9fa07bf1196b78e1d43ad999 (diff)
downloadrails-76cd4cb27e2ec197c7f62082334d5d7211fd2d19.tar.gz
rails-76cd4cb27e2ec197c7f62082334d5d7211fd2d19.tar.bz2
rails-76cd4cb27e2ec197c7f62082334d5d7211fd2d19.zip
Memoize in the endpoint.
-rw-r--r--.gitignore2
-rw-r--r--actionpack/lib/action_controller/metal.rb15
-rw-r--r--actionpack/vendor/gems/environment.rb94
3 files changed, 11 insertions, 100 deletions
diff --git a/.gitignore b/.gitignore
index e8485acfec..f0e6c8385f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,5 +30,5 @@ railties/guides/output
actionpack/bin
*/vendor/gems/gems
*/vendor/gems/specifications
-*/vendor/gems/environment.rb
+actionpack/vendor/gems/environment.rb
*/vendor/gems/dirs/specifications \ No newline at end of file
diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb
index 296d359391..6aa4fe6019 100644
--- a/actionpack/lib/action_controller/metal.rb
+++ b/actionpack/lib/action_controller/metal.rb
@@ -79,6 +79,15 @@ module ActionController
end
class ActionEndpoint
+ @@endpoints = Hash.new {|h,k| h[k] = Hash.new {|h,k| h[k] = {} } }
+
+ def self.for(controller, action, stack)
+ @@endpoints[controller][action][stack] ||= begin
+ endpoint = new(controller, action)
+ stack.build(endpoint)
+ end
+ end
+
def initialize(controller, action)
@controller, @action = controller, action
end
@@ -108,11 +117,7 @@ module ActionController
# ==== Returns
# Proc:: A rack application
def self.action(name)
- @actions ||= {}
- @actions[name.to_s] ||= begin
- endpoint = ActionEndpoint.new(self, name)
- middleware_stack.build(endpoint)
- end
+ ActionEndpoint.for(self, name, middleware_stack)
end
end
end
diff --git a/actionpack/vendor/gems/environment.rb b/actionpack/vendor/gems/environment.rb
deleted file mode 100644
index 5f7e483c3b..0000000000
--- a/actionpack/vendor/gems/environment.rb
+++ /dev/null
@@ -1,94 +0,0 @@
-# DO NOT MODIFY THIS FILE
-module Bundler
- dir = File.dirname(__FILE__)
-
- ENV["PATH"] = "#{dir}/../../bin:#{ENV["PATH"]}"
- ENV["RUBYOPT"] = "-r#{__FILE__} #{ENV["RUBYOPT"]}"
-
- $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/gems/activemodel-3.0.pre/bin")
- $LOAD_PATH.unshift File.expand_path("#{dir}/../../../activemodel/lib")
- $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/gems/activesupport-3.0.pre/bin")
- $LOAD_PATH.unshift File.expand_path("#{dir}/../../../activesupport/lib")
- $LOAD_PATH.unshift File.expand_path("#{dir}/gems/rack-1.0.0/bin")
- $LOAD_PATH.unshift File.expand_path("#{dir}/gems/rack-1.0.0/lib")
- $LOAD_PATH.unshift File.expand_path("#{dir}/gems/rack-test-0.4.2/bin")
- $LOAD_PATH.unshift File.expand_path("#{dir}/gems/rack-test-0.4.2/lib")
-
- @gemfile = "#{dir}/../../Gemfile"
-
- require "rubygems"
-
- @bundled_specs = {}
- @bundled_specs["rack"] = eval(File.read("#{dir}/specifications/rack-1.0.0.gemspec"))
- @bundled_specs["rack"].loaded_from = "#{dir}/specifications/rack-1.0.0.gemspec"
- @bundled_specs["activemodel"] = eval(File.read("#{dir}/dirs/specifications/activemodel-3.0.pre.gemspec"))
- @bundled_specs["activemodel"].loaded_from = "#{dir}/dirs/specifications/activemodel-3.0.pre.gemspec"
- @bundled_specs["rack-test"] = eval(File.read("#{dir}/specifications/rack-test-0.4.2.gemspec"))
- @bundled_specs["rack-test"].loaded_from = "#{dir}/specifications/rack-test-0.4.2.gemspec"
- @bundled_specs["activesupport"] = eval(File.read("#{dir}/dirs/specifications/activesupport-3.0.pre.gemspec"))
- @bundled_specs["activesupport"].loaded_from = "#{dir}/dirs/specifications/activesupport-3.0.pre.gemspec"
-
- def self.add_specs_to_loaded_specs
- Gem.loaded_specs.merge! @bundled_specs
- end
-
- def self.add_specs_to_index
- @bundled_specs.each do |name, spec|
- Gem.source_index.add_spec spec
- end
- end
-
- add_specs_to_loaded_specs
- add_specs_to_index
-
- def self.require_env(env = nil)
- context = Class.new do
- def initialize(env) @env = env && env.to_s ; end
- def method_missing(*) ; end
- def only(env)
- old, @only = @only, _combine_onlys(env)
- yield
- @only = old
- end
- def except(env)
- old, @except = @except, _combine_excepts(env)
- yield
- @except = old
- end
- def gem(name, *args)
- opt = args.last || {}
- only = _combine_onlys(opt[:only] || opt["only"])
- except = _combine_excepts(opt[:except] || opt["except"])
- files = opt[:require_as] || opt["require_as"] || name
-
- return unless !only || only.any? {|e| e == @env }
- return if except && except.any? {|e| e == @env }
-
- files.each { |f| require f }
- yield if block_given?
- true
- end
- private
- def _combine_onlys(only)
- return @only unless only
- only = [only].flatten.compact.uniq.map { |o| o.to_s }
- only &= @only if @only
- only
- end
- def _combine_excepts(except)
- return @except unless except
- except = [except].flatten.compact.uniq.map { |o| o.to_s }
- except |= @except if @except
- except
- end
- end
- context.new(env && env.to_s).instance_eval(File.read(@gemfile))
- end
-end
-
-module Gem
- def source_index.refresh!
- super
- Bundler.add_specs_to_index
- end
-end