lib/thinking_sphinx/context.rb in thinking-sphinx-1.3.7 vs lib/thinking_sphinx/context.rb in thinking-sphinx-1.3.8

- old
+ new

@@ -5,10 +5,11 @@ @indexed_models = [] end def prepare load_models + add_indexed_models if cached? end def define_indexes indexed_models.each { |model| model.constantize.define_indexes @@ -30,18 +31,26 @@ }.collect { |klass| klass.name } end private + def cached? + defined?(Rails) && + Rails::VERSION::STRING.to_f > 2.1 && + Rails.configuration.cache_classes + end + + def add_indexed_models + Object.subclasses_of(ActiveRecord::Base).each do |klass| + add_indexed_model klass if klass.has_sphinx_indexes? + end + end + # Make sure all models are loaded - without reloading any that # ActiveRecord::Base is already aware of (otherwise we start to hit some # messy dependencies issues). # def load_models - return if defined?(Rails) && - Rails::VERSION::STRING.to_f > 2.1 && - Rails.configuration.cache_classes - ThinkingSphinx::Configuration.instance.model_directories.each do |base| Dir["#{base}**/*.rb"].each do |file| model_name = file.gsub(/^#{base}([\w_\/\\]+)\.rb/, '\1') next if model_name.nil?