Hi Glenn,
When I have done something like this before, it has been by adding a hook
that keeps track whenever that code is included/invoked/etc. For example,
in a module I might have
module WhosThere
def self.included(klass)
@classes ||= []
@classes << klass
end
end
Then the WhosThere module has a list of all of the classes that have invoked
it.
For something like acts_as_solr where you don't want to touch the code
itself, you could do a monkey patch of some sort like
class ActiveRecord::Base
cattr_accessor :solr_classes
def acts_as_solr_with_hook
ActiveRecord::Base.solr_classes ||= []
ActiveRecord::Base.solr_classes << self
acts_as_solr_without_hook
end
alias_method_chain :acts_as_solr, :hook
end
You would then have your list in ActiveRecord::Base.solr_classes
(Caution, this code written off the top of my head, may need some tweaking
to actually get it to work)
-Kevin
On Thu, Dec 16, 2010 at 9:27 AM, Glenn Little <[email protected]> wrote:
> In particular, I'm wondering if there's an easy way in a rails app to
> get a list of all model classes that have "acts_as_solr" defined in
> them. I can do a "grep -r" in my models directory and stuff the
> results into a list after proper capitalization/munging, but I'd like
> to do this programmatically, self-contained in the app itself.
>
> Thanks...
>
> -glenn
>
> --
> SD Ruby mailing list
> [email protected]
> http://groups.google.com/group/sdruby
--
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby