ActiveSupport
ActiveSupport is the library of utility methods that Rails uses. We examine them in
detail here for two reasons. First, they can be useful to our application code??”we can
directly use many of these libraries and methods to our advantage when writing Rails
applications. Secondly, we can learn many things about Ruby programming by dissecting
these parts. They are small and relatively easy to digest.
Dependencies dependencies.rb
Dependencies autoloads missing constants by trying to find the file associated with the
constant. When you attempt to access a nonexistent constant, such as Message, Dependencies
will try to find and load message.rb from any directory in Dependencies.load_paths.
Dependencies defines Module#const_missing and Class#const_missing, which both proxy to
Dependencies.load_missing_constant(const_parent, const_id). That method searches the
load paths for a file with the appropriate name; if found, Dependencies loads the file and
ensures that it defined the appropriate constant.
Alternatively, Rails will create an empty module to satisfy nesting in the case of nested
models and controllers. If a directory named app/models/store/ exists, Store will be created
as an empty module, by the following process:
1. Some piece of code references the undefined constant Store.
2. Ruby calls const_missing.
Deprecation
58 | Chapter 2: ActiveSupport and RailTies
3.
Pages:
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97