Method: Sunspot::Adapters::InstanceAdapter.for
- Defined in:
- lib/sunspot/adapters.rb
.for(clazz) ⇒ Object
Find the best InstanceAdapter implementation that adapts the given class. Starting with the class and then moving up the ancestor chain, looks for registered InstanceAdapter implementations.
Parameters
- clazz<Class>
-
The class to find an InstanceAdapter for
Returns
- Class
-
Subclass of InstanceAdapter, or nil if none found
Raises
- Sunspot::NoAdapterError
-
If no adapter is registered for this class
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/sunspot/adapters.rb', line 118 def for(clazz) #:nodoc: original_class_name = clazz.name clazz.ancestors.each do |ancestor_class| next if ancestor_class.name.nil? || ancestor_class.name.empty? class_name = ancestor_class.name.to_sym return instance_adapters[class_name] if instance_adapters[class_name] end raise(Sunspot::NoAdapterError, "No adapter is configured for #{original_class_name} or its superclasses. See the documentation for Sunspot::Adapters") end |