Re: Find all ActiveRecord::Base subclasses?


#1

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.


#2

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:

http://lists.rubyonrails.org/mailman/listinfo/rails


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Luke Amdor
removed_email_address@domain.invalid

/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 removed_email_address@domain.invalid


#3

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.


#4

It will. But

ObjectSpace.each_object(Class) do |c|
p c if c.ancestors.include? ActiveRecord::Base
end

will not.

Kent.


#5

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


#6

John

Give a try to
http://www.ruby-forum.com/forum/3

note: it doesn’t contain the whole archive, as this project started
recently.

Alain


#7

Kent S. 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 ?


#8

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


#9

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