Forum: Ruby on Rails Re: Find all ActiveRecord::Base subclasses?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bdf2290f0b1d87cb0853966e7e51606b?d=identicon&s=25 Andrew O'Brien (Guest)
on 2005-12-12 22:04
(Received via mailing list)
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.
8b6e9047a02f6756e0dcb36863463b5b?d=identicon&s=25 Luke Amdor (Guest)
on 2005-12-12 22:22
(Received via mailing list)
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
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

--
Luke Amdor
luke@absoluterubbish.net

/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@wall.org>
3ccecc71b9fb0a3d7f00a0bef6f0a63a?d=identicon&s=25 Kent Sibilev (Guest)
on 2005-12-12 22:28
(Received via mailing list)
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.
Ccfe7d097475a32dc3ff78d6fc42c852?d=identicon&s=25 List Recv (lstrecv)
on 2005-12-12 22:38
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 ?
3ccecc71b9fb0a3d7f00a0bef6f0a63a?d=identicon&s=25 Kent Sibilev (Guest)
on 2005-12-12 23:13
(Received via mailing list)
It will. But

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

will not.

Kent.
09b87770d7b50f3a7f913984477eea23?d=identicon&s=25 speechexpert (Guest)
on 2005-12-12 23:19
(Received via mailing list)
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
0091f92762685860109bbcb02edfdf27?d=identicon&s=25 Alain Ravet (Guest)
on 2005-12-13 13:25
(Received via mailing list)
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
8d50470327c9f59b275f532026b465ec?d=identicon&s=25 Todd Breiholz (Guest)
on 2005-12-17 13:41
(Received via mailing list)
8147308d52b3110ac467cc66717e576f?d=identicon&s=25 Craig Larmer (Guest)
on 2005-12-17 13:41
(Received via mailing list)
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
This topic is locked and can not be replied to.