aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2004-11-30 18:52:20 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2004-11-30 18:52:20 +0000
commitd82f73ecabe71fc3814eff0bd26f4f431f690266 (patch)
tree568ad503cf10c54acd2a945c317d81887b1eb20b /activerecord/lib
parent5b38d8557122723aa7c11c28d4c2c93464982766 (diff)
downloadrails-d82f73ecabe71fc3814eff0bd26f4f431f690266.tar.gz
rails-d82f73ecabe71fc3814eff0bd26f4f431f690266.tar.bz2
rails-d82f73ecabe71fc3814eff0bd26f4f431f690266.zip
Abolished ActionController::Base.require_or_load in favor of require_dependency and ActiveRecord::Base.require_or_load in favor of require_association. Both methods are now also available in the global namespace when you need to require dependencies or associations outside of whats done automatically.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@32 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb2
-rwxr-xr-xactiverecord/lib/active_record/base.rb14
2 files changed, 12 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 6e9dd3ac47..b015699fba 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -562,7 +562,7 @@ module ActiveRecord
def require_association_class(class_name)
begin
- require_or_load(Inflector.underscore(class_name))
+ require_association(Inflector.underscore(class_name))
rescue LoadError
# Failed to load the associated class -- let's hope the developer is doing the requiring himself.
end
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 7238f97067..6d3b07a435 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -546,13 +546,15 @@ module ActiveRecord #:nodoc:
end
# Loads the <tt>file_name</tt> if reload_associations is true or requires if it's false.
- def require_or_load(file_name)
+ def require_association(file_name)
if !associations_loaded.include?(file_name)
associations_loaded << file_name
reload_associations ? silence_warnings { load("#{file_name}.rb") } : require(file_name)
end
end
+ Object.send(:define_method, :require_association) { |file_name| ActiveRecord::Base.require_association(file_name) }
+
# Resets the list of dependencies loaded (typically to be called by the end of a request), so when require_or_load is
# called for that dependency it'll be loaded anew.
def reset_associations_loaded
@@ -782,10 +784,16 @@ module ActiveRecord #:nodoc:
self.class.column_methods_hash[method.to_sym] || respond_to_without_attributes?(method)
end
- def require_or_load(file_name)
- self.class.require_or_load(file_name)
+ # Loads the <tt>file_name</tt> if reload_associations is true or requires if it's false.
+ def require_association(file_name)
+ if !associations_loaded.include?(file_name)
+ associations_loaded << file_name
+ reload_associations ? silence_warnings { load("#{file_name}.rb") } : require(file_name)
+ end
end
+ Object.send(:define_method, :require_association) { |file_name| ActiveRecord::Base.require_association(file_name) }
+
private
def create_or_update
if new_record? then create else update end