Skip to content

Commit 20b015b

Browse files
committed
Documenting the application configuration module.
1 parent 9c03cd9 commit 20b015b

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

activerecord/lib/active_record/application_configuration.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,47 @@ module ActiveRecord
22
module ApplicationConfiguration
33
extend ActiveSupport::Concern
44

5+
# The <tt>ApplicationConfiguration</tt> module allows you to control different
6+
# configurations that have been set on a particular namespace or model. The
7+
# <tt>ApplicationRecord</tt> class for a particular model can be accessed and used
8+
# for finding configurations.
9+
#
10+
# To access this class, you can use the <tt>application_record</tt> method on
11+
# any subclass of <tt>ActiveRecord::Base</tt>. For example:
12+
#
13+
# class MyModel < ApplicationRecord
14+
# end
15+
#
16+
# ActiveRecord::Base.application_record # => ApplicationRecord
17+
# MyModel.application_record # => ApplicationRecord
18+
#
19+
# Moreover, you can use namespacing of modules with the <tt>application_record</tt>
20+
# method.
21+
#
22+
# module MyNamespace
23+
# class ApplicationRecord < ::ApplicationRecord
24+
# end
25+
#
26+
# class MyModel < ApplicationRecord
27+
# end
28+
# end
29+
#
30+
# ActiveRecord::Base.application_record # => ApplicationRecord
31+
# MyNamespace::MyModel.application_record # => MyNamespace::ApplicationRecord
32+
#
33+
# You may additionally pass in a class to <tt>application_record</tt>, and
34+
# it will look for the configuration of that class. For example:
35+
#
36+
# ActiveRecord::Base.application_record(MyNamespace::MyModel)
37+
# # => MyNamespace::ApplicationRecord
38+
#
39+
# If the class that is passed into <tt>application_record</tt> does not have
40+
# a configuration associated with it, then the method will return the value
41+
# that would have been returned without any argument.
42+
#
43+
# ActiveRecord::Base.application_reocrd('something_with_no_config')
44+
# # => ApplicationRecord
45+
#
546
module ClassMethods
647
def configs_from(mod)
748
app_record = self

0 commit comments

Comments
 (0)