Module: ActiveSupport::Autoload
- Included in:
- AbstractController, ActionController, ActionController::Caching, ActionDispatch, ActionDispatch::Http, ActionMailer, ActionView, ActionView::Helpers, ActionView::Template, ActiveModel, ActiveModel::Serializers, ActiveRecord, ActiveRecord::AttributeMethods, ActiveRecord::ConnectionAdapters, ActiveRecord::Locking, ActiveRecord::Scoping, ActiveResource, ActiveSupport, HTML
- Defined in:
- activesupport/lib/active_support/dependencies/autoload.rb
Constant Summary collapse
- @@autoloads =
{}
- @@under_path =
nil
- @@at_path =
nil
- @@eager_autoload =
false
Class Method Summary collapse
Instance Method Summary collapse
- #autoload(const_name, path = @@at_path) ⇒ Object
- #autoload_at(path) ⇒ Object
- #autoload_under(path) ⇒ Object
- #autoloads ⇒ Object
- #eager_autoload ⇒ Object
Class Method Details
.eager_autoload! ⇒ Object
42 43 44 |
# File 'activesupport/lib/active_support/dependencies/autoload.rb', line 42 def self.eager_autoload! @@autoloads.values.each { |file| require file } end |
Instance Method Details
#autoload(const_name, path = @@at_path) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'activesupport/lib/active_support/dependencies/autoload.rb', line 11 def autoload(const_name, path = @@at_path) full = [self.name, @@under_path, const_name.to_s, path].compact.join("::") location = path || Inflector.underscore(full) if @@eager_autoload @@autoloads[const_name] = location end super const_name, location end |
#autoload_at(path) ⇒ Object
28 29 30 31 32 33 |
# File 'activesupport/lib/active_support/dependencies/autoload.rb', line 28 def autoload_at(path) @@at_path, old_path = path, @@at_path yield ensure @@at_path = old_path end |
#autoload_under(path) ⇒ Object
21 22 23 24 25 26 |
# File 'activesupport/lib/active_support/dependencies/autoload.rb', line 21 def autoload_under(path) @@under_path, old_path = path, @@under_path yield ensure @@under_path = old_path end |
#autoloads ⇒ Object
46 47 48 |
# File 'activesupport/lib/active_support/dependencies/autoload.rb', line 46 def autoloads @@autoloads end |
#eager_autoload ⇒ Object
35 36 37 38 39 40 |
# File 'activesupport/lib/active_support/dependencies/autoload.rb', line 35 def eager_autoload old_eager, @@eager_autoload = @@eager_autoload, true yield ensure @@eager_autoload = old_eager end |