I''m taking a look at tackling the namespace pollution issues surrounding engines and plugins at the moment. I came across this ticket wherein Jeremy K. points out that the lack of an autoloading feature of models within modules is by design. For example: class TypoEngine::Category < ActiveRecord::Base; end will not be autoloaded if a controller, for example, were to reference it like so: @category = TypoEngine::Category.new What, exactly, is by design here? Is it a speed enhancement? It seems to make so much more sense from a best practices perspective to avoid namespace collisions. Duane Johnson (canadaduane) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails-core/attachments/20051109/f2011b4d/attachment.html
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Nov 9, 2005, at 11:40 AM, Duane Johnson wrote:> I''m taking a look at tackling the namespace pollution issues > surrounding engines and plugins at the moment. I came across this > ticket wherein Jeremy K. points out that the lack of an autoloading > feature of models within modules is by design.s/design/implementation/ From the same ticket: "it''d be great to have a clear, sensible convention for nesting paths and modules." Maybe Nicholas knows more.> What, exactly, is by design here? Is it a speed enhancement? It > seems to make so much more sense from a best practices perspective > to avoid namespace collisions.Of course. See above. jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (Darwin) iD8DBQFDcmlLAQHALep9HFYRAk/kAKCzRJKyxFBK0YafKOjN6AJpu3OmrwCgj5eU HElbfjIHsIdqBtD5WEqoYZU=+7Ts -----END PGP SIGNATURE-----
Hi Duane, The technical issue is that non-controller classes aren''t placed in ::Controllers. This is by design, since they are not controllers. Because of this, the lookup for Category is thrown upwards until it reaches :: and Rails'' dependency loading kicks in. The real issue is that Rails does not have an opinionated setup about how code organization should be done, and where loaded classes should go in the namespace. By this, I mean that Rails does not really care if your class is in models/foo.rb or models/namespace/foo.rb. Likewise, it does not care too much if you say Category from inside a module or out. At one point I had a setup where this stuff did matter. If you put "class Foo; end" in models/namespace/foo.rb, Rails would load your file and compile it inside module Namespace. This was a fair bit of magic, and probably too much. Anyhow, it seems like I''m rambling. The point is that Jeremy and I both agree that we would like the layout of the app to reflect the Ruby convention more closely, and that there should be a more opinionated relation between the Ruby namespace and the source layout. However we also think this is an issue to be addressed post 1.0. Cheers, Nicholas Seckar