diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-11-24 11:14:24 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-11-24 11:14:24 -0600 |
commit | 7254d23764f7abe8023f3daeb07d99ea1c8e777a (patch) | |
tree | 4c1981119e1da9b9c98e8e2d9cf8a3b7dcfcb887 /activerecord | |
parent | 426a86ab1e4fc2488215a9adab4511a59646a413 (diff) | |
download | rails-7254d23764f7abe8023f3daeb07d99ea1c8e777a.tar.gz rails-7254d23764f7abe8023f3daeb07d99ea1c8e777a.tar.bz2 rails-7254d23764f7abe8023f3daeb07d99ea1c8e777a.zip |
Autoload ActiveRecord files
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record.rb | 78 | ||||
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 22 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 11 | ||||
-rwxr-xr-x | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 1 | ||||
-rw-r--r-- | activerecord/lib/active_record/serialization.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/ar_schema_test.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/schema_dumper_test.rb | 1 |
7 files changed, 61 insertions, 55 deletions
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb index 7fdef17a45..584349659e 100644 --- a/activerecord/lib/active_record.rb +++ b/activerecord/lib/active_record.rb @@ -31,51 +31,45 @@ rescue LoadError end end -require 'active_record/base' -require 'active_record/named_scope' -require 'active_record/observer' -require 'active_record/query_cache' -require 'active_record/validations' -require 'active_record/callbacks' -require 'active_record/reflection' -require 'active_record/associations' -require 'active_record/association_preload' -require 'active_record/aggregations' -require 'active_record/transactions' -require 'active_record/timestamp' -require 'active_record/locking/optimistic' -require 'active_record/locking/pessimistic' -require 'active_record/migration' -require 'active_record/schema' -require 'active_record/calculations' -require 'active_record/serialization' -require 'active_record/attribute_methods' -require 'active_record/dirty' -require 'active_record/dynamic_finder_match' +module ActiveRecord + # TODO: Review explicit loads to see if they will automatically be handled by the initilizer. + def self.load_all! + [Base, DynamicFinderMatch, ConnectionAdapters::AbstractAdapter] + end -ActiveRecord::Base.class_eval do - extend ActiveRecord::QueryCache - include ActiveRecord::Validations - include ActiveRecord::Locking::Optimistic - include ActiveRecord::Locking::Pessimistic - include ActiveRecord::AttributeMethods - include ActiveRecord::Dirty - include ActiveRecord::Callbacks - include ActiveRecord::Observing - include ActiveRecord::Timestamp - include ActiveRecord::Associations - include ActiveRecord::NamedScope - include ActiveRecord::AssociationPreload - include ActiveRecord::Aggregations - include ActiveRecord::Transactions - include ActiveRecord::Reflection - include ActiveRecord::Calculations - include ActiveRecord::Serialization -end + autoload :Aggregations, 'active_record/aggregations' + autoload :AssociationPreload, 'active_record/association_preload' + autoload :Associations, 'active_record/associations' + autoload :AttributeMethods, 'active_record/attribute_methods' + autoload :Base, 'active_record/base' + autoload :Calculations, 'active_record/calculations' + autoload :Callbacks, 'active_record/callbacks' + autoload :Dirty, 'active_record/dirty' + autoload :DynamicFinderMatch, 'active_record/dynamic_finder_match' + autoload :Migration, 'active_record/migration' + autoload :NamedScope, 'active_record/named_scope' + autoload :Observing, 'active_record/observer' + autoload :QueryCache, 'active_record/query_cache' + autoload :Reflection, 'active_record/reflection' + autoload :Schema, 'active_record/schema' + autoload :SchemaDumper, 'active_record/schema_dumper' + autoload :Serialization, 'active_record/serialization' + autoload :TestCase, 'active_record/test_case' + autoload :Timestamp, 'active_record/timestamp' + autoload :Transactions, 'active_record/transactions' + autoload :Validations, 'active_record/validations' -require 'active_record/connection_adapters/abstract_adapter' + module Locking + autoload :Optimistic, 'active_record/locking/optimistic' + autoload :Pessimistic, 'active_record/locking/pessimistic' + end -require 'active_record/schema_dumper' + module ConnectionAdapters + autoload :AbstractAdapter, 'active_record/connection_adapters/abstract_adapter' + end +end require 'active_record/i18n_interpolation_deprecation' I18n.load_path << File.dirname(__FILE__) + '/active_record/locale/en.yml' + +ActiveRecord.load_all! diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 7f7819115c..63e28a43ab 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1,13 +1,3 @@ -require 'active_record/associations/association_proxy' -require 'active_record/associations/association_collection' -require 'active_record/associations/belongs_to_association' -require 'active_record/associations/belongs_to_polymorphic_association' -require 'active_record/associations/has_one_association' -require 'active_record/associations/has_many_association' -require 'active_record/associations/has_many_through_association' -require 'active_record/associations/has_and_belongs_to_many_association' -require 'active_record/associations/has_one_through_association' - module ActiveRecord class HasManyThroughAssociationNotFoundError < ActiveRecordError #:nodoc: def initialize(owner_class_name, reflection) @@ -75,6 +65,18 @@ module ActiveRecord # See ActiveRecord::Associations::ClassMethods for documentation. module Associations # :nodoc: + # These classes will be loaded when associatoins are created. + # So there is no need to eager load them. + autoload :AssociationCollection, 'active_record/associations/association_collection' + autoload :AssociationProxy, 'active_record/associations/association_proxy' + autoload :BelongsToAssociation, 'active_record/associations/belongs_to_association' + autoload :BelongsToPolymorphicAssociation, 'active_record/associations/belongs_to_polymorphic_association' + autoload :HasAndBelongsToManyAssociation, 'active_record/associations/has_and_belongs_to_many_association' + autoload :HasManyAssociation, 'active_record/associations/has_many_association' + autoload :HasManyThroughAssociation, 'active_record/associations/has_many_through_association' + autoload :HasOneAssociation, 'active_record/associations/has_one_association' + autoload :HasOneThroughAssociation, 'active_record/associations/has_one_through_association' + def self.included(base) base.extend(ClassMethods) end diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 6692235a78..1e7cac8371 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2978,4 +2978,15 @@ module ActiveRecord #:nodoc: value end end + + Base.class_eval do + extend QueryCache + include Validations + include Locking::Optimistic, Locking::Pessimistic + include AttributeMethods + include Dirty + include Callbacks, Observing, Timestamp + include Associations, AssociationPreload, NamedScope + include Aggregations, Transactions, Reflection, Calculations, Serialization + end end diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 092d8f2268..cab77fc031 100755 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -3,6 +3,7 @@ require 'date' require 'bigdecimal' require 'bigdecimal/util' +# TODO: Autoload these files require 'active_record/connection_adapters/abstract/schema_definitions' require 'active_record/connection_adapters/abstract/schema_statements' require 'active_record/connection_adapters/abstract/database_statements' diff --git a/activerecord/lib/active_record/serialization.rb b/activerecord/lib/active_record/serialization.rb index 332cda1e16..cef067de5f 100644 --- a/activerecord/lib/active_record/serialization.rb +++ b/activerecord/lib/active_record/serialization.rb @@ -95,4 +95,4 @@ module ActiveRecord #:nodoc: end require 'active_record/serializers/xml_serializer' -require 'active_record/serializers/json_serializer'
\ No newline at end of file +require 'active_record/serializers/json_serializer' diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb index 431dc7a141..4c1589d965 100644 --- a/activerecord/test/cases/ar_schema_test.rb +++ b/activerecord/test/cases/ar_schema_test.rb @@ -1,5 +1,4 @@ require "cases/helper" -require 'active_record/schema' if ActiveRecord::Base.connection.supports_migrations? diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index ee7e285a73..17e4c755ce 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -1,5 +1,4 @@ require "cases/helper" -require 'active_record/schema_dumper' require 'stringio' |