I''m wondering was the most Rubyish way to get an array of all subclasses of ActiveRecord::Base. This should be possible through Ruby''s reflection capabilities, right? Or is there a method in ActiveRecord? Thanks.
You might query the ObjectSpace. Kent. On Monday 12 December 2005 15:01, Andrew O''Brien wrote:> I''m wondering was the most Rubyish way to get an array of all > subclasses of ActiveRecord::Base. This should be possible through > Ruby''s reflection capabilities, right? Or is there a method in > ActiveRecord? > > Thanks. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Andrew O''Brien wrote:> I''m wondering was the most Rubyish way to get an array of all > subclasses of ActiveRecord::Base. This should be possible through > Ruby''s reflection capabilities, right? Or is there a method in > ActiveRecord? > > Thanks.You could do something like this: module ActiveRecord class Base def self.get_subclasses @@subclasses end end end ActiveRecord::Base.get_subclasses ActiveRecord does have a ActiveRecord::Base.subclasses method, but its private. Regards, Blair -- Blair Zajac, Ph.D. <blair-szbw9MROnEZWk0Htik3J/w@public.gmane.org> Subversion and Orca training and consulting http://www.orcaware.com/svn/
Wouldn''t that return the objects of class ActiveRecord::Base instead of the classes themselves? Looking through the Base.rb, I saw that there''s a method called "subclasses" that''s protected. Just to clarify my original question, I''m trying to do this from a class outside of ActiveRecord::Base.> You might query the ObjectSpace.> Kent.> On Monday 12 December 2005 15:01, Andrew O''Brien wrote: >> I''m wondering was the most Rubyish way to get an array of all >> subclasses of ActiveRecord::Base. This should be possible through >> Ruby''s reflection capabilities, right? Or is there a method in >> ActiveRecord? >> >> Thanks. >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails
Try.. objects = [] ObjectSpace.each_object(Class) {|obj| objects << obj if obj.superclass == ActiveRecord::Base} Luke On Mon, Dec 12, 2005 at 04:02:43PM -0500, Andrew O''Brien wrote:> Wouldn''t that return the objects of class ActiveRecord::Base instead > of the classes themselves? > > Looking through the Base.rb, I saw that there''s a method called > "subclasses" that''s protected. Just to clarify my original question, > I''m trying to do this from a class outside of ActiveRecord::Base. > > > You might query the ObjectSpace. > > > Kent. > > > On Monday 12 December 2005 15:01, Andrew O''Brien wrote: > >> I''m wondering was the most Rubyish way to get an array of all > >> subclasses of ActiveRecord::Base. This should be possible through > >> Ruby''s reflection capabilities, right? Or is there a method in > >> ActiveRecord? > >> > >> Thanks. > >> _______________________________________________ > >> Rails mailing list > >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Luke Amdor luke-Hk3lrmVzaNfBeN7rVTv1SdHuzzzSOjJt@public.gmane.org /usr/bin/fortune | And we can always supply them with a program that makes identical files into links to a single file. -- Larry Wall in <199709292012.NAA09616-jGImRhG+IA0@public.gmane.org>
On Monday 12 December 2005 16:02, Andrew O''Brien wrote:> Wouldn''t that return the objects of class ActiveRecord::Base instead > of the classes themselves? >Not necessarily. ObjectSpace.each_object(Class) do |c| p c if c.superclass == ActiveRecord::Base end Note that it assumes that all models have been already loaded. Kent.
OK - Here''s my issue My Outlook Expres is getting bogged down by the 50,000 or so emails on Ruby and Rails ml''s. I find searching these lists a valuable source of information. I tried to search the archives directly, and my impression is the search engine was slow and unreliable. How do you all solve this problem, since it must be a common issue. ?? Thanks in advance, John B
Kent Sibilev wrote:> On Monday 12 December 2005 16:02, Andrew O''Brien wrote: >> Wouldn''t that return the objects of class ActiveRecord::Base instead >> of the classes themselves? >> > > Not necessarily. > > ObjectSpace.each_object(Class) do |c| > p c if c.superclass == ActiveRecord::Base > end > > Note that it assumes that all models have been already loaded. > > Kent.Won''t this miss HappyCustomer < Customer < ActiveRecord::Base ? -- Posted via http://www.ruby-forum.com/.
Try searching on Gmane: ruby general list: http://dir.gmane.org/gmane.comp.lang.ruby.general rails list: http://dir.gmane.org/gmane.comp.lang.ruby.rails Todd On 12/12/05, speechexpert <speechexpert-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org> wrote:> > OK - Here''s my issue > My Outlook Expres is getting bogged down by the 50,000 or so emails on > Ruby > and Rails ml''s. > I find searching these lists a valuable source of information. > I tried to search the archives directly, and my impression is the search > engine was slow and unreliable. > > How do you all solve this problem, since it must be a common issue. > ?? > > Thanks in advance, > > John B > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
For offline access you may be able to use Google Desktop (desktop.google.com). It says it has Outlook integration although I haven''t used it myself. Cheers, CL On 12/13/05, speechexpert <speechexpert-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org> wrote:> > OK - Here''s my issue > My Outlook Expres is getting bogged down by the 50,000 or so emails on > Ruby > and Rails ml''s. > I find searching these lists a valuable source of information. > I tried to search the archives directly, and my impression is the search > engine was slow and unreliable. > > How do you all solve this problem, since it must be a common issue. > ?? > > Thanks in advance, > > John B > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
It will. But ObjectSpace.each_object(Class) do |c| p c if c.ancestors.include? ActiveRecord::Base end will not. Kent. On Monday 12 December 2005 16:38, List Recv wrote:> Kent Sibilev wrote: > > On Monday 12 December 2005 16:02, Andrew O''Brien wrote: > >> Wouldn''t that return the objects of class ActiveRecord::Base instead > >> of the classes themselves? > > > > Not necessarily. > > > > ObjectSpace.each_object(Class) do |c| > > p c if c.superclass == ActiveRecord::Base > > end > > > > Note that it assumes that all models have been already loaded. > > > > Kent. > > Won''t this miss HappyCustomer < Customer < ActiveRecord::Base ?
Thanks for all your responses. I think the method that uses Ruby''s open classes looks like the best one for my purposes.