Skip to content

Commit 61e440d

Browse files
wangjohnrafaelfranca
authored andcommitted
Creating ApplicationModel methods.
These methods will be used by the ApplicationModel to send the correct configuration.
1 parent b2ff6b0 commit 61e440d

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

activerecord/lib/active_record.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module ActiveRecord
3333
extend ActiveSupport::Autoload
3434

3535
autoload :Attribute
36+
autoload :ApplicationConfiguration
3637
autoload :Base
3738
autoload :Callbacks
3839
autoload :Core
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module ActiveRecord
2+
module ApplicationConfiguration
3+
extend ActiveSupport::Concern
4+
5+
module ClassMethods
6+
def configs_from(application)
7+
app_model = self
8+
9+
application.singleton_class.instance_eval do
10+
define_method(:application_model) { app_model }
11+
end
12+
13+
define_singleton_method(:configs_from_application) { application }
14+
end
15+
end
16+
end
17+
end

activerecord/lib/active_record/base.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ class Base
284284
extend Delegation::DelegateCache
285285

286286
include Core
287+
include ApplicationConfiguration
287288
include Persistence
288289
include ReadonlyAttributes
289290
include ModelSchema
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
class ApplicationModel < ActiveRecord::Base
22
self.abstract_class = true
3+
configs_from Rails.application
34
end

railties/test/application/rake_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_should_not_eager_load_model_for_rake
9999
end
100100

101101
def test_code_statistics_sanity
102-
assert_match "Code LOC: 8 Test LOC: 0 Code to Test Ratio: 1:0.0",
102+
assert_match "Code LOC: 9 Test LOC: 0 Code to Test Ratio: 1:0.0",
103103
Dir.chdir(app_path){ `rake stats` }
104104
end
105105

0 commit comments

Comments
 (0)