From 8e1f1ee44241838c2b701ad2622d98c9c41ea268 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 12 Dec 2004 16:14:20 +0000 Subject: Moved require_association to associations.rb and added methods for resetting the inheritable attributes on subclasses git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@125 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/associations.rb | 20 +++++++++++++- activerecord/lib/active_record/base.rb | 32 +++------------------- .../support/class_inheritable_attributes.rb | 7 +++-- 3 files changed, 28 insertions(+), 31 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 6f6da10a01..6ba7b80102 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -3,6 +3,10 @@ require 'active_record/associations/has_many_association' require 'active_record/associations/has_and_belongs_to_many_association' require 'active_record/deprecated_associations' +unless Object.respond_to?(:require_association) + Object.send(:define_method, :require_association) { |file_name| ActiveRecord::Base.require_association(file_name) } +end + module ActiveRecord module Associations # :nodoc: def self.append_features(base) @@ -447,6 +451,20 @@ module ActiveRecord deprecated_has_collection_method(association_name) end + # Loads the file_name 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 + + # Resets the list of dependencies loaded (typically to be called by the end of a request), so when require_association is + # called for that dependency it'll be loaded anew. + def reset_associations_loaded + associations_loaded = [] + end + private # Raises an exception if an invalid option has been specified to prevent misspellings from slipping through def validate_options(valid_option_keys, supplied_option_keys) @@ -571,4 +589,4 @@ module ActiveRecord end end end -end +end \ No newline at end of file diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 2346aa19e9..465a1ed8cf 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -3,10 +3,6 @@ require 'active_record/support/class_inheritable_attributes' require 'active_record/support/inflector' require 'yaml' -unless Object.respond_to?(:require_association) - Object.send(:define_method, :require_association) { |file_name| ActiveRecord::Base.require_association(file_name) } -end - module ActiveRecord #:nodoc: class ActiveRecordError < StandardError #:nodoc: end @@ -192,6 +188,10 @@ module ActiveRecord #:nodoc: end @@subclasses = {} + + def self.subclasses + @@subclasses.values.flatten + end cattr_accessor :configurations @@primary_key_prefix_type = {} @@ -559,20 +559,6 @@ module ActiveRecord #:nodoc: return result end - # Loads the file_name 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 - - # Resets the list of dependencies loaded (typically to be called by the end of a request), so when require_association is - # called for that dependency it'll be loaded anew. - def reset_associations_loaded - associations_loaded = [] - end - private # Finder methods must instantiate through this method to work with the single-table inheritance model # that makes it possible to create objects of different types from the same table. @@ -840,16 +826,6 @@ module ActiveRecord #:nodoc: def respond_to?(method) self.class.column_methods_hash[method.to_sym] || respond_to_without_attributes?(method) end - - # Loads the file_name 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 diff --git a/activerecord/lib/active_record/support/class_inheritable_attributes.rb b/activerecord/lib/active_record/support/class_inheritable_attributes.rb index ee69646da0..201932cf2d 100644 --- a/activerecord/lib/active_record/support/class_inheritable_attributes.rb +++ b/activerecord/lib/active_record/support/class_inheritable_attributes.rb @@ -28,10 +28,13 @@ module ClassInheritableAttributes # :nodoc: inheritable_attributes[key] end + def reset_inheritable_attributes + inheritable_attributes.clear + end + private def inherited(child) @@classes[child] = inheritable_attributes.dup - end - + end end end -- cgit v1.2.3