Skip to content
This repository
Browse code

Memoize in the endpoint.

  • Loading branch information...
commit 76cd4cb27e2ec197c7f62082334d5d7211fd2d19 1 parent ddb4600
Yehuda Katz authored September 12, 2009
2  .gitignore
@@ -30,5 +30,5 @@ railties/guides/output
30 30
 actionpack/bin
31 31
 */vendor/gems/gems
32 32
 */vendor/gems/specifications
33  
-*/vendor/gems/environment.rb
  33
+actionpack/vendor/gems/environment.rb
34 34
 */vendor/gems/dirs/specifications
15  actionpack/lib/action_controller/metal.rb
@@ -79,6 +79,15 @@ def to_a
79 79
     end
80 80
 
81 81
     class ActionEndpoint
  82
+      @@endpoints = Hash.new {|h,k| h[k] = Hash.new {|h,k| h[k] = {} } }
  83
+
  84
+      def self.for(controller, action, stack)
  85
+        @@endpoints[controller][action][stack] ||= begin
  86
+          endpoint = new(controller, action)
  87
+          stack.build(endpoint)
  88
+        end
  89
+      end
  90
+
82 91
       def initialize(controller, action)
83 92
         @controller, @action = controller, action
84 93
       end
@@ -108,11 +117,7 @@ def self.middleware
108 117
     # ==== Returns
109 118
     # Proc:: A rack application
110 119
     def self.action(name)
111  
-      @actions ||= {}
112  
-      @actions[name.to_s] ||= begin
113  
-        endpoint = ActionEndpoint.new(self, name)
114  
-        middleware_stack.build(endpoint)
115  
-      end
  120
+      ActionEndpoint.for(self, name, middleware_stack)
116 121
     end
117 122
   end
118 123
 end
94  actionpack/vendor/gems/environment.rb
... ...
@@ -1,94 +0,0 @@
1  
-# DO NOT MODIFY THIS FILE
2  
-module Bundler
3  
-  dir = File.dirname(__FILE__)
4  
-
5  
-  ENV["PATH"]     = "#{dir}/../../bin:#{ENV["PATH"]}"
6  
-  ENV["RUBYOPT"]  = "-r#{__FILE__} #{ENV["RUBYOPT"]}"
7  
-
8  
-  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/gems/activemodel-3.0.pre/bin")
9  
-  $LOAD_PATH.unshift File.expand_path("#{dir}/../../../activemodel/lib")
10  
-  $LOAD_PATH.unshift File.expand_path("#{dir}/dirs/gems/activesupport-3.0.pre/bin")
11  
-  $LOAD_PATH.unshift File.expand_path("#{dir}/../../../activesupport/lib")
12  
-  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/rack-1.0.0/bin")
13  
-  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/rack-1.0.0/lib")
14  
-  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/rack-test-0.4.2/bin")
15  
-  $LOAD_PATH.unshift File.expand_path("#{dir}/gems/rack-test-0.4.2/lib")
16  
-
17  
-  @gemfile = "#{dir}/../../Gemfile"
18  
-
19  
-  require "rubygems"
20  
-
21  
-  @bundled_specs = {}
22  
-  @bundled_specs["rack"] = eval(File.read("#{dir}/specifications/rack-1.0.0.gemspec"))
23  
-  @bundled_specs["rack"].loaded_from = "#{dir}/specifications/rack-1.0.0.gemspec"
24  
-  @bundled_specs["activemodel"] = eval(File.read("#{dir}/dirs/specifications/activemodel-3.0.pre.gemspec"))
25  
-  @bundled_specs["activemodel"].loaded_from = "#{dir}/dirs/specifications/activemodel-3.0.pre.gemspec"
26  
-  @bundled_specs["rack-test"] = eval(File.read("#{dir}/specifications/rack-test-0.4.2.gemspec"))
27  
-  @bundled_specs["rack-test"].loaded_from = "#{dir}/specifications/rack-test-0.4.2.gemspec"
28  
-  @bundled_specs["activesupport"] = eval(File.read("#{dir}/dirs/specifications/activesupport-3.0.pre.gemspec"))
29  
-  @bundled_specs["activesupport"].loaded_from = "#{dir}/dirs/specifications/activesupport-3.0.pre.gemspec"
30  
-
31  
-  def self.add_specs_to_loaded_specs
32  
-    Gem.loaded_specs.merge! @bundled_specs
33  
-  end
34  
-
35  
-  def self.add_specs_to_index
36  
-    @bundled_specs.each do |name, spec|
37  
-      Gem.source_index.add_spec spec
38  
-    end
39  
-  end
40  
-
41  
-  add_specs_to_loaded_specs
42  
-  add_specs_to_index
43  
-
44  
-  def self.require_env(env = nil)
45  
-    context = Class.new do
46  
-      def initialize(env) @env = env && env.to_s ; end
47  
-      def method_missing(*) ; end
48  
-      def only(env)
49  
-        old, @only = @only, _combine_onlys(env)
50  
-        yield
51  
-        @only = old
52  
-      end
53  
-      def except(env)
54  
-        old, @except = @except, _combine_excepts(env)
55  
-        yield
56  
-        @except = old
57  
-      end
58  
-      def gem(name, *args)
59  
-        opt = args.last || {}
60  
-        only = _combine_onlys(opt[:only] || opt["only"])
61  
-        except = _combine_excepts(opt[:except] || opt["except"])
62  
-        files = opt[:require_as] || opt["require_as"] || name
63  
-
64  
-        return unless !only || only.any? {|e| e == @env }
65  
-        return if except && except.any? {|e| e == @env }
66  
-
67  
-        files.each { |f| require f }
68  
-        yield if block_given?
69  
-        true
70  
-      end
71  
-      private
72  
-      def _combine_onlys(only)
73  
-        return @only unless only
74  
-        only = [only].flatten.compact.uniq.map { |o| o.to_s }
75  
-        only &= @only if @only
76  
-        only
77  
-      end
78  
-      def _combine_excepts(except)
79  
-        return @except unless except
80  
-        except = [except].flatten.compact.uniq.map { |o| o.to_s }
81  
-        except |= @except if @except
82  
-        except
83  
-      end
84  
-    end
85  
-    context.new(env && env.to_s).instance_eval(File.read(@gemfile))
86  
-  end
87  
-end
88  
-
89  
-module Gem
90  
-  def source_index.refresh!
91  
-    super
92  
-    Bundler.add_specs_to_index
93  
-  end
94  
-end

0 notes on commit 76cd4cb

Please sign in to comment.
Something went wrong with that request. Please try again.