aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-12-12 18:41:26 -0600
committerJoshua Peek <josh@joshpeek.com>2009-12-12 18:41:26 -0600
commit018dafe574d370165547516ffef43394e11ab4da (patch)
tree6ad2359b8f00dabee5e1fd46bebb59fc72530f36 /activesupport/lib
parentee395fe626760e897abd9e881b54d3cc3f407d31 (diff)
downloadrails-018dafe574d370165547516ffef43394e11ab4da.tar.gz
rails-018dafe574d370165547516ffef43394e11ab4da.tar.bz2
rails-018dafe574d370165547516ffef43394e11ab4da.zip
Allow autoloads to opt out of eager loading
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/dependencies/autoload.rb20
1 files changed, 16 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/dependencies/autoload.rb b/activesupport/lib/active_support/dependencies/autoload.rb
index 973875f895..96ab04c61a 100644
--- a/activesupport/lib/active_support/dependencies/autoload.rb
+++ b/activesupport/lib/active_support/dependencies/autoload.rb
@@ -2,16 +2,18 @@ require "active_support/inflector/methods"
module ActiveSupport
module Autoload
-
@@autoloads = {}
@@under_path = nil
@@at_path = nil
+ @@autoload_defer = false
def autoload(const_name, path = @@at_path)
full = [self.name, @@under_path, const_name.to_s, path].compact.join("::")
location = path || Inflector.underscore(full)
- @@autoloads[const_name] = location
+ unless @@autoload_defer
+ @@autoloads[const_name] = location
+ end
super const_name, location
end
@@ -29,9 +31,19 @@ module ActiveSupport
@@at_path = old_path
end
+ def deferrable
+ old_defer, @@autoload_defer = @@autoload_defer, true
+ yield
+ ensure
+ @@autoload_defer = old_defer
+ end
+
def self.eager_autoload!
- @@autoloads.values.each {|file| require file }
+ @@autoloads.values.each { |file| require file }
end
+ def autoloads
+ @@autoloads
+ end
end
-end \ No newline at end of file
+end