Skip to content
Newer
Older
100644 201 lines (163 sloc) 7.76 KB
23ad1ef @jeremy Rationalize railtie dependencies: AC uses AV; AR uses AMo; and Rails …
jeremy authored Feb 4, 2010
1 require "active_record"
2 require "rails"
3 require "active_model/railtie"
4
38aeb15 Moving out some framework specific initializers into the framework li…
Carlhuda authored Dec 23, 2009
5 # For now, action_controller must always be present with
6 # rails, so let's make sure that it gets required before
7 # here. This is needed for correctly setting up the middleware.
8 # In the future, this might become an optional require.
ae7ada1 Some railties cleanup:
Carl Lerche authored Dec 31, 2009
9 require "action_controller/railtie"
38aeb15 Moving out some framework specific initializers into the framework li…
Carlhuda authored Dec 23, 2009
10
11 module ActiveRecord
2b7f084 @rizwanreza Adds basic description and title.
rizwanreza authored Jun 16, 2010
12 # = Active Record Railtie
b21012b nodoc AR::Railtie [ci skip]
Francesco Rodriguez authored Sep 21, 2012
13 class Railtie < Rails::Railtie # :nodoc:
395d664 @josevalim Move application configuration to the application configuration objec…
josevalim authored Mar 26, 2010
14 config.active_record = ActiveSupport::OrderedOptions.new
97db79a @josevalim Remove ActiveRecord runtime logging from ActionPack and place in Acti…
josevalim authored Dec 27, 2009
15
f851352 @drogus Added config.app_generators to allow configuring application's genera…
drogus authored Sep 29, 2010
16 config.app_generators.orm :active_record, :migration => true,
cfbe595 @drogus Use application's generators defaults as engine defaults to not force…
drogus authored Oct 28, 2010
17 :timestamps => true
f15bbcf Move the ActiveRecord generator settings into the Railtie
Carl Lerche authored Jan 28, 2010
18
c211d90 @jeremy Revert "Just add connection management middleware if running in a con…
jeremy authored Aug 20, 2010
19 config.app_middleware.insert_after "::ActionDispatch::Callbacks",
20 "ActiveRecord::QueryCache"
21
22 config.app_middleware.insert_after "::ActionDispatch::Callbacks",
23 "ActiveRecord::ConnectionAdapters::ConnectionManagement"
9cfeefb @wycats Reorganized initializers a bit to enable better hooks for common case…
wycats authored May 15, 2010
24
b4359bc @josevalim Allow rescue responses to be configured through a railtie.
josevalim authored Dec 1, 2011
25 config.action_dispatch.rescue_responses.merge!(
26 'ActiveRecord::RecordNotFound' => :not_found,
27 'ActiveRecord::StaleObjectError' => :conflict,
28 'ActiveRecord::RecordInvalid' => :unprocessable_entity,
29 'ActiveRecord::RecordNotSaved' => :unprocessable_entity
30 )
31
2801786 @josevalim Get rid of config.preload_frameworks in favor of config.eager_load_na…
josevalim authored Aug 1, 2012
32
e35c67a @kennyj The use_schema_cache_dump configuration moved to ActiveRecord.
kennyj authored Aug 1, 2012
33 config.active_record.use_schema_cache_dump = true
34
2801786 @josevalim Get rid of config.preload_frameworks in favor of config.eager_load_na…
josevalim authored Aug 1, 2012
35 config.eager_load_namespaces << ActiveRecord
36
49c800b Move the ActiveRecord related rake tasks into the AR gem.
Carl Lerche authored Dec 28, 2009
37 rake_tasks do
c0ba0f0 @kennyj Fix #5847 and #4045 on master.
kennyj authored May 29, 2012
38 require "active_record/base"
d1d7c86 @drogus Don't require having Rails.application to run database tasks
drogus authored Apr 24, 2013
39
20f1495 @drogus Don't require Rails.env in order to use AR::Tasks::DatabaseTasks
drogus authored Apr 24, 2013
40 ActiveRecord::Tasks::DatabaseTasks.env = Rails.env
d1d7c86 @drogus Don't require having Rails.application to run database tasks
drogus authored Apr 24, 2013
41 ActiveRecord::Tasks::DatabaseTasks.db_dir = Rails.application.config.paths["db"].first
42 ActiveRecord::Tasks::DatabaseTasks.seed_loader = Rails.application
43 ActiveRecord::Tasks::DatabaseTasks.database_configuration = Rails.application.config.database_configuration
44 ActiveRecord::Tasks::DatabaseTasks.migrations_paths = Rails.application.paths['db/migrate'].to_a
4522761 @drogus Use DatabaseTasks.fixtures_path instead of FIXTURES_PATH in db.rake
drogus authored Apr 24, 2013
45 ActiveRecord::Tasks::DatabaseTasks.fixtures_path = File.join Rails.root, 'test', 'fixtures'
d1d7c86 @drogus Don't require having Rails.application to run database tasks
drogus authored Apr 24, 2013
46
89f558c @drogus Check if APP_RAKEFILE is defined
drogus authored May 16, 2013
47 if defined?(APP_RAKEFILE) && engine = Rails::Engine.find(find_engine_path(APP_RAKEFILE))
d1d7c86 @drogus Don't require having Rails.application to run database tasks
drogus authored Apr 24, 2013
48 if engine.paths['db/migrate'].existent
49 ActiveRecord::Tasks::DatabaseTasks.migrations_paths += engine.paths['db/migrate'].to_a
50 end
51 end
52
10a2638 @jeremy Fix up AR extension by using Railties module instead of Rails and req…
jeremy authored Dec 30, 2009
53 load "active_record/railties/databases.rake"
49c800b Move the ActiveRecord related rake tasks into the AR gem.
Carl Lerche authored Dec 29, 2009
54 end
55
b9bba55 @josevalim Remove defined?(ActiveRecord) and use the railtie hook instead.
josevalim authored May 4, 2011
56 # When loading console, force ActiveRecord::Base to be loaded
57 # to avoid cross references when loading a constant for the
58 # first time. Also, make it output to STDERR.
52e01fc @josevalim Everyone receives app as argument for consistency.
josevalim authored May 25, 2011
59 console do |app|
60 require "active_record/railties/console_sandbox" if app.sandbox?
c0ba0f0 @kennyj Fix #5847 and #4045 on master.
kennyj authored May 28, 2012
61 require "active_record/base"
983bf6d @tenderlove restored logging to the log file and display on the console
tenderlove authored Jan 20, 2012
62 console = ActiveSupport::Logger.new(STDERR)
a0da46e @tenderlove pushed broadcasting down to a module
tenderlove authored Jan 20, 2012
63 Rails.logger.extend ActiveSupport::Logger.broadcast console
fa98eca @josevalim Add console hook to force ActiveRecord::Base to be loaded when consol…
josevalim authored Jul 17, 2010
64 end
65
d338a0f @vipulnsward MOAR cleanups.
vipulnsward authored Mar 14, 2013
66 runner do
cc7dd66 @kennyj Use runner hook to load ActiveRecord::Base.
kennyj authored May 29, 2012
67 require "active_record/base"
68 end
69
c8cc8a9 @josevalim Moved more configuration away from bootstrap.
josevalim authored Jan 22, 2010
70 initializer "active_record.initialize_timezone" do
4aded43 @wycats Replace the placeholder base_hook API with on_load. To specify some c…
wycats authored Mar 29, 2010
71 ActiveSupport.on_load(:active_record) do
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored Mar 7, 2010
72 self.time_zone_aware_attributes = true
73 self.default_timezone = :utc
74 end
c8cc8a9 @josevalim Moved more configuration away from bootstrap.
josevalim authored Jan 22, 2010
75 end
76
3b6f659 @josevalim Add active_model/railtie back to generated boot.rb, add models back t…
josevalim authored Jan 25, 2010
77 initializer "active_record.logger" do
4aded43 @wycats Replace the placeholder base_hook API with on_load. To specify some c…
wycats authored Mar 30, 2010
78 ActiveSupport.on_load(:active_record) { self.logger ||= ::Rails.logger }
3b6f659 @josevalim Add active_model/railtie back to generated boot.rb, add models back t…
josevalim authored Jan 25, 2010
79 end
80
d338a0f @vipulnsward MOAR cleanups.
vipulnsward authored Mar 14, 2013
81 initializer "active_record.migration_error" do
96f19f6 @schneems raise error for pending migration
schneems authored Jun 5, 2012
82 if config.active_record.delete(:migration_error) == :page_load
83 config.app_middleware.insert_after "::ActionDispatch::Callbacks",
84 "ActiveRecord::Migration::CheckPending"
85 end
86 end
87
b7a695c @arunagw removed warning: shadowing outer local variable
arunagw authored Sep 8, 2012
88 initializer "active_record.check_schema_cache_dump" do
e35c67a @kennyj The use_schema_cache_dump configuration moved to ActiveRecord.
kennyj authored Aug 1, 2012
89 if config.active_record.delete(:use_schema_cache_dump)
90 config.after_initialize do |app|
91 ActiveSupport.on_load(:active_record) do
92 filename = File.join(app.config.paths["db"].first, "schema_cache.dump")
b21012b nodoc AR::Railtie [ci skip]
Francesco Rodriguez authored Sep 22, 2012
93
e35c67a @kennyj The use_schema_cache_dump configuration moved to ActiveRecord.
kennyj authored Aug 1, 2012
94 if File.file?(filename)
95 cache = Marshal.load File.binread filename
96 if cache.version == ActiveRecord::Migrator.current_version
9e4c41c @jonleighton Remove ActiveRecord::Model
jonleighton authored Oct 26, 2012
97 self.connection.schema_cache = cache
e35c67a @kennyj The use_schema_cache_dump configuration moved to ActiveRecord.
kennyj authored Aug 1, 2012
98 else
4ad90b0 @fxn make clear that expired db/schema_cache.dump are ignored
fxn authored Sep 24, 2012
99 warn "Ignoring db/schema_cache.dump because it has expired. The current schema version is #{ActiveRecord::Migrator.current_version}, but the one in the cache is #{cache.version}."
e35c67a @kennyj The use_schema_cache_dump configuration moved to ActiveRecord.
kennyj authored Aug 1, 2012
100 end
101 end
102 end
103 end
104 end
105 end
106
38aeb15 Moving out some framework specific initializers into the framework li…
Carlhuda authored Dec 23, 2009
107 initializer "active_record.set_configs" do |app|
4aded43 @wycats Replace the placeholder base_hook API with on_load. To specify some c…
wycats authored Mar 30, 2010
108 ActiveSupport.on_load(:active_record) do
42cfacf @pixeltrix Gracefully handle upgrading apps with mass assigment configs
pixeltrix authored Nov 9, 2012
109 begin
110 old_behavior, ActiveSupport::Deprecation.behavior = ActiveSupport::Deprecation.behavior, :stderr
111 whitelist_attributes = app.config.active_record.delete(:whitelist_attributes)
112
113 if respond_to?(:mass_assignment_sanitizer=)
114 mass_assignment_sanitizer = nil
115 else
116 mass_assignment_sanitizer = app.config.active_record.delete(:mass_assignment_sanitizer)
117 end
118
119 unless whitelist_attributes.nil? && mass_assignment_sanitizer.nil?
120 ActiveSupport::Deprecation.warn <<-EOF.strip_heredoc, []
121 Model based mass assignment security has been extracted
122 out of Rails into a gem. Please use the new recommended protection model for
123 params or add `protected_attributes` to your Gemfile to use the old one.
124
125 To disable this message remove the `whitelist_attributes` option from your
126 `config/application.rb` file and any `mass_assignment_sanitizer` options
127 from your `config/environments/*.rb` files.
128
d3688e0 @senny remove AR auto-explain (config.auto_explain_threshold_in_seconds)
senny authored Feb 24, 2013
129 See http://guides.rubyonrails.org/security.html#mass-assignment for more information.
130 EOF
131 end
132
133 unless app.config.active_record.delete(:auto_explain_threshold_in_seconds).nil?
134 ActiveSupport::Deprecation.warn <<-EOF.strip_heredoc, []
135 The Active Record auto explain feature has been removed.
136
137 To disable this message remove the `active_record.auto_explain_threshold_in_seconds`
138 option from the `config/environments/*.rb` config file.
139
140 See http://guides.rubyonrails.org/4_0_release_notes.html for more information.
42cfacf @pixeltrix Gracefully handle upgrading apps with mass assigment configs
pixeltrix authored Nov 9, 2012
141 EOF
142 end
f862376 @rafaelfranca Gracefully handle upgrading apps with observers
rafaelfranca authored Nov 28, 2012
143
144 unless app.config.active_record.delete(:observers).nil?
145 ActiveSupport::Deprecation.warn <<-EOF.strip_heredoc, []
146 Active Record Observers has been extracted out of Rails into a gem.
54aed23 @lucasmazza Fix typo in the Observers deprecation message. [ci skip]
lucasmazza authored Nov 28, 2012
147 Please use callbacks or add `rails-observers` to your Gemfile to use observers.
f862376 @rafaelfranca Gracefully handle upgrading apps with observers
rafaelfranca authored Nov 28, 2012
148
149 To disable this message remove the `observers` option from your
150 `config/application.rb` or from your initializers.
151
d3688e0 @senny remove AR auto-explain (config.auto_explain_threshold_in_seconds)
senny authored Feb 24, 2013
152 See http://guides.rubyonrails.org/4_0_release_notes.html for more information.
f862376 @rafaelfranca Gracefully handle upgrading apps with observers
rafaelfranca authored Nov 28, 2012
153 EOF
154 end
42cfacf @pixeltrix Gracefully handle upgrading apps with mass assigment configs
pixeltrix authored Nov 9, 2012
155 ensure
156 ActiveSupport::Deprecation.behavior = old_behavior
157 end
158
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored Mar 7, 2010
159 app.config.active_record.each do |k,v|
160 send "#{k}=", v
161 end
38aeb15 Moving out some framework specific initializers into the framework li…
Carlhuda authored Dec 23, 2009
162 end
163 end
164
165 # This sets the database configuration from Configuration#database_configuration
166 # and then establishes the connection.
167 initializer "active_record.initialize_database" do |app|
4aded43 @wycats Replace the placeholder base_hook API with on_load. To specify some c…
wycats authored Mar 30, 2010
168 ActiveSupport.on_load(:active_record) do
dd5a80d @josevalim Remove hard coded references to Active Record in railties
josevalim authored Mar 2, 2013
169 self.configurations = app.config.database_configuration || {}
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored Mar 7, 2010
170 establish_connection
171 end
38aeb15 Moving out some framework specific initializers into the framework li…
Carlhuda authored Dec 23, 2009
172 end
173
10a2638 @jeremy Fix up AR extension by using Railties module instead of Rails and req…
jeremy authored Dec 31, 2009
174 # Expose database runtime to controller for logging.
d338a0f @vipulnsward MOAR cleanups.
vipulnsward authored Mar 14, 2013
175 initializer "active_record.log_runtime" do
10a2638 @jeremy Fix up AR extension by using Railties module instead of Rails and req…
jeremy authored Dec 31, 2009
176 require "active_record/railties/controller_runtime"
4aded43 @wycats Replace the placeholder base_hook API with on_load. To specify some c…
wycats authored Mar 30, 2010
177 ActiveSupport.on_load(:action_controller) do
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored Mar 7, 2010
178 include ActiveRecord::Railties::ControllerRuntime
179 end
10a2638 @jeremy Fix up AR extension by using Railties module instead of Rails and req…
jeremy authored Dec 31, 2009
180 end
181
283a087 @josevalim Clean up the cache before the request in case we are running in the r…
josevalim authored Dec 15, 2011
182 initializer "active_record.set_reloader_hooks" do |app|
61826bc @jonleighton refactor
jonleighton authored Jun 15, 2012
183 hook = app.config.reload_classes_only_on_change ? :to_prepare : :to_cleanup
283a087 @josevalim Clean up the cache before the request in case we are running in the r…
josevalim authored Dec 15, 2011
184
61826bc @jonleighton refactor
jonleighton authored Jun 15, 2012
185 ActiveSupport.on_load(:active_record) do
186 ActionDispatch::Reloader.send(hook) do
85cc712 @tenderlove only clear caches if we are actually connected to the database
tenderlove authored Nov 12, 2012
187 if ActiveRecord::Base.connected?
188 ActiveRecord::Base.clear_reloadable_connections!
189 ActiveRecord::Base.clear_cache!
190 end
39d6f9e @wycats Make many parts of Rails lazy. In order to facilitate this,
wycats authored Mar 7, 2010
191 end
8c8942e @josevalim Move Dispatcher setup to Railties and add instrumentation hook.
josevalim authored Jan 14, 2010
192 end
193 end
194
fa1d9a8 @josevalim Speed up development by only reloading classes if dependencies files …
josevalim authored Dec 12, 2011
195 initializer "active_record.add_watchable_files" do |app|
4756ced @kennyj Should use app.paths instead of specific path.
kennyj authored Oct 8, 2012
196 path = app.paths["db"].first
197 config.watchable_files.concat ["#{path}/schema.rb", "#{path}/structure.sql"]
fa1d9a8 @josevalim Speed up development by only reloading classes if dependencies files …
josevalim authored Dec 12, 2011
198 end
38aeb15 Moving out some framework specific initializers into the framework li…
Carlhuda authored Dec 23, 2009
199 end
10a2638 @jeremy Fix up AR extension by using Railties module instead of Rails and req…
jeremy authored Dec 31, 2009
200 end
Something went wrong with that request. Please try again.