diff options
author | Mikel Lindsaar <raasdnil@gmail.com> | 2009-12-17 11:24:02 +1100 |
---|---|---|
committer | Mikel Lindsaar <raasdnil@gmail.com> | 2009-12-17 11:24:02 +1100 |
commit | 186cd7bc530f705b889c27f3680ab48c7c10a6f3 (patch) | |
tree | 76955e442615d77ee05ef2a8260c5373e1cac680 /activesupport/lib/active_support/dependencies/autoload.rb | |
parent | 5f2395041d1578433fa825ed5c6f26a201f2203d (diff) | |
parent | b9d4ceb43c9497fb1c47d8b1e1e6a24a9e157384 (diff) | |
download | rails-186cd7bc530f705b889c27f3680ab48c7c10a6f3.tar.gz rails-186cd7bc530f705b889c27f3680ab48c7c10a6f3.tar.bz2 rails-186cd7bc530f705b889c27f3680ab48c7c10a6f3.zip |
Merge branch 'rails'
Conflicts:
actionmailer/lib/action_mailer.rb
actionmailer/lib/action_mailer/delivery_method/smtp.rb
Diffstat (limited to 'activesupport/lib/active_support/dependencies/autoload.rb')
-rw-r--r-- | activesupport/lib/active_support/dependencies/autoload.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/dependencies/autoload.rb b/activesupport/lib/active_support/dependencies/autoload.rb new file mode 100644 index 0000000000..96ab04c61a --- /dev/null +++ b/activesupport/lib/active_support/dependencies/autoload.rb @@ -0,0 +1,49 @@ +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) + + unless @@autoload_defer + @@autoloads[const_name] = location + end + super const_name, location + end + + def autoload_under(path) + @@under_path, old_path = path, @@under_path + yield + ensure + @@under_path = old_path + end + + def autoload_at(path) + @@at_path, old_path = path, @@at_path + yield + ensure + @@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 } + end + + def autoloads + @@autoloads + end + end +end |