aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-12-25 12:09:13 +0100
committerJosé Valim <jose.valim@gmail.com>2009-12-25 12:09:13 +0100
commiteb8e627c6918dae53c7ab8b9208e72ff64d20348 (patch)
tree4f153960d158c119ebdcef7a3a02c407e4b82dd0 /activerecord/lib
parent4b8330d2d50ae4de14dd43ffbea4d91804553140 (diff)
parent1c66f85eb6cd80053cf60889634a8c39c21b11a1 (diff)
downloadrails-eb8e627c6918dae53c7ab8b9208e72ff64d20348.tar.gz
rails-eb8e627c6918dae53c7ab8b9208e72ff64d20348.tar.bz2
rails-eb8e627c6918dae53c7ab8b9208e72ff64d20348.zip
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record.rb116
-rw-r--r--activerecord/lib/active_record/notifications.rb5
-rw-r--r--activerecord/lib/active_record/rails.rb59
3 files changed, 123 insertions, 57 deletions
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb
index 2376bbd04a..196b87c0ac 100644
--- a/activerecord/lib/active_record.rb
+++ b/activerecord/lib/active_record.rb
@@ -35,82 +35,94 @@ require 'arel'
module ActiveRecord
extend ActiveSupport::Autoload
- autoload :VERSION
-
- autoload :ActiveRecordError, 'active_record/base'
- autoload :ConnectionNotEstablished, 'active_record/base'
-
- autoload :Aggregations
- autoload :AssociationPreload
- autoload :Associations
- autoload :AttributeMethods
- autoload :Attributes
- autoload :AutosaveAssociation
- autoload :Relation
- autoload :Base
- autoload :Batches
- autoload :Calculations
- autoload :Callbacks
- autoload :DynamicFinderMatch
- autoload :DynamicScopeMatch
- autoload :Migration
- autoload :Migrator, 'active_record/migration'
- autoload :NamedScope
- autoload :NestedAttributes
- autoload :Observer
- autoload :QueryCache
- autoload :Reflection
- autoload :Schema
- autoload :SchemaDumper
- autoload :Serialization
- autoload :SessionStore
- autoload :StateMachine
- autoload :Timestamp
- autoload :Transactions
- autoload :Types
- autoload :Validations
+ eager_autoload do
+ autoload :VERSION
+
+ autoload :ActiveRecordError, 'active_record/base'
+ autoload :ConnectionNotEstablished, 'active_record/base'
+
+ autoload :Aggregations
+ autoload :AssociationPreload
+ autoload :Associations
+ autoload :AttributeMethods
+ autoload :Attributes
+ autoload :AutosaveAssociation
+ autoload :Relation
+ autoload :Base
+ autoload :Batches
+ autoload :Calculations
+ autoload :Callbacks
+ autoload :DynamicFinderMatch
+ autoload :DynamicScopeMatch
+ autoload :Migration
+ autoload :Migrator, 'active_record/migration'
+ autoload :NamedScope
+ autoload :NestedAttributes
+ autoload :Observer
+ autoload :QueryCache
+ autoload :Reflection
+ autoload :Schema
+ autoload :SchemaDumper
+ autoload :Serialization
+ autoload :SessionStore
+ autoload :StateMachine
+ autoload :Timestamp
+ autoload :Transactions
+ autoload :Types
+ autoload :Validations
+ end
module AttributeMethods
extend ActiveSupport::Autoload
- autoload :BeforeTypeCast
- autoload :Dirty
- autoload :PrimaryKey
- autoload :Query
- autoload :Read
- autoload :TimeZoneConversion
- autoload :Write
+ eager_autoload do
+ autoload :BeforeTypeCast
+ autoload :Dirty
+ autoload :PrimaryKey
+ autoload :Query
+ autoload :Read
+ autoload :TimeZoneConversion
+ autoload :Write
+ end
end
module Attributes
extend ActiveSupport::Autoload
- autoload :Aliasing
- autoload :Store
- autoload :Typecasting
+ eager_autoload do
+ autoload :Aliasing
+ autoload :Store
+ autoload :Typecasting
+ end
end
module Type
extend ActiveSupport::Autoload
- autoload :Number, 'active_record/types/number'
- autoload :Object, 'active_record/types/object'
- autoload :Serialize, 'active_record/types/serialize'
- autoload :TimeWithZone, 'active_record/types/time_with_zone'
- autoload :Unknown, 'active_record/types/unknown'
+ eager_autoload do
+ autoload :Number, 'active_record/types/number'
+ autoload :Object, 'active_record/types/object'
+ autoload :Serialize, 'active_record/types/serialize'
+ autoload :TimeWithZone, 'active_record/types/time_with_zone'
+ autoload :Unknown, 'active_record/types/unknown'
+ end
end
module Locking
extend ActiveSupport::Autoload
- autoload :Optimistic
- autoload :Pessimistic
+ eager_autoload do
+ autoload :Optimistic
+ autoload :Pessimistic
+ end
end
module ConnectionAdapters
extend ActiveSupport::Autoload
- autoload :AbstractAdapter
+ eager_autoload do
+ autoload :AbstractAdapter
+ end
end
end
diff --git a/activerecord/lib/active_record/notifications.rb b/activerecord/lib/active_record/notifications.rb
deleted file mode 100644
index 562a5b91f4..0000000000
--- a/activerecord/lib/active_record/notifications.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require 'active_support/notifications'
-
-ActiveSupport::Notifications.subscribe("sql") do |name, before, after, result, instrumenter_id, payload|
- ActiveRecord::Base.connection.log_info(payload[:sql], name, after - before)
-end
diff --git a/activerecord/lib/active_record/rails.rb b/activerecord/lib/active_record/rails.rb
new file mode 100644
index 0000000000..ddbc555113
--- /dev/null
+++ b/activerecord/lib/active_record/rails.rb
@@ -0,0 +1,59 @@
+# For now, action_controller must always be present with
+# rails, so let's make sure that it gets required before
+# here. This is needed for correctly setting up the middleware.
+# In the future, this might become an optional require.
+require "action_controller/rails"
+
+module ActiveRecord
+ class Plugin < Rails::Plugin
+ plugin_name :active_record
+
+ initializer "active_record.set_configs" do |app|
+ app.config.active_record.each do |k,v|
+ ActiveRecord::Base.send "#{k}=", v
+ end
+ end
+
+ # This sets the database configuration from Configuration#database_configuration
+ # and then establishes the connection.
+ initializer "active_record.initialize_database" do |app|
+ ActiveRecord::Base.configurations = app.config.database_configuration
+ ActiveRecord::Base.establish_connection
+ end
+
+ initializer "active_record.initialize_timezone" do
+ ActiveRecord::Base.time_zone_aware_attributes = true
+ ActiveRecord::Base.default_timezone = :utc
+ end
+
+ # Setup database middleware after initializers have run
+ initializer "active_record.initialize_database_middleware" do |app|
+ middleware = app.config.middleware
+ if middleware.include?(ActiveRecord::SessionStore)
+ middleware.insert_before ActiveRecord::SessionStore, ActiveRecord::ConnectionAdapters::ConnectionManagement
+ middleware.insert_before ActiveRecord::SessionStore, ActiveRecord::QueryCache
+ else
+ middleware.use ActiveRecord::ConnectionAdapters::ConnectionManagement
+ middleware.use ActiveRecord::QueryCache
+ end
+ end
+
+ initializer "active_record.load_observers" do
+ ActiveRecord::Base.instantiate_observers
+ end
+
+ # TODO: ActiveRecord::Base.logger should delegate to its own config.logger
+ initializer "active_record.logger" do
+ ActiveRecord::Base.logger ||= Rails.logger
+ end
+
+ initializer "active_record.notifications" do
+ require 'active_support/notifications'
+
+ ActiveSupport::Notifications.subscribe("sql") do |name, before, after, result, instrumenter_id, payload|
+ ActiveRecord::Base.connection.log_info(payload[:sql], name, after - before)
+ end
+ end
+
+ end
+end \ No newline at end of file