pat/thinking-sphinx — pull request #405 by robg (2013-01-03 02:38:56+00:00)
Title: Check for already loaded classes before trying to constantize an STI sub...

...class in a subfolder and skip logging NameErrors and LoadErrors to STDERR

One of our applications makes some heavy use of STI and we were seeing a few error messages being written to STDERR by ThinkingSphinx::Context#load_models even though the indices were being generated correctly. I believe the problem stems from trying to force loading models while the application is currently in the middle of loading.

For instance, we have something roughly similar to:

```ruby
class A < ActiveRecord::Base
define_index do
....
end
end

define B < A
end

define C < B
end

define SomeObserver < ActiveRecord::Observer
observes :b, :c
end
```

What I see is that first, SomeObserver is loaded by rails, which in turn tries to constantize 'B', which triggers loading of class A and the definition of A's index. Defining the index triggers a call to #load_models which will eventually try to constantize 'C', which will error out with a NameError on 'B'. My hypothesis is that this a cycle prevention mechanism in the class loader to avoid infinite loops.

In any case, this patch simply removes the logging to STDERR since the behavior has always been to just ignore the error and move along. I also moved the AR::Base.descendants check into the begin..end block so that it can be a part of the retry logic.