Class: Showroom::Search::Suggestion
- Defined in:
- lib/showroom/models/search/suggestion.rb
Overview
Base class for all search suggestion types.
Subclasses that correspond to a fully-loadable model override Suggestion.complete_model_class to declare which model to fetch. Calling #load on a suggestion that has no model raises NoMethodError.
Direct Known Subclasses
ArticleSuggestion, CollectionSuggestion, PageSuggestion, ProductSuggestion, QuerySuggestion
Instance Attribute Summary
Attributes inherited from Resource
Class Method Summary collapse
-
.complete_model_class ⇒ Class
Override in subclasses to declare the corresponding full model class.
Instance Method Summary collapse
-
#load ⇒ Resource
Fetches the full model record for this suggestion.
-
#loadable_identifier ⇒ String
Returns the identifier used to fetch the full record (defaults to the
handleattribute).
Methods inherited from Resource
#==, #[], has_many, has_one, #initialize, #inspect, main_attr_keys, main_attrs, #method_missing, #respond_to_missing?, #to_h
Constructor Details
This class inherits a constructor from Showroom::Resource
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Showroom::Resource
Class Method Details
.complete_model_class ⇒ Class
Override in subclasses to declare the corresponding full model class.
24 25 26 |
# File 'lib/showroom/models/search/suggestion.rb', line 24 def complete_model_class raise NoMethodError, "#{name} has no associated model — #load is not available" end |
Instance Method Details
#load ⇒ Resource
Fetches the full model record for this suggestion.
Delegates to the model class declared by complete_model_class, finding by #loadable_identifier.
45 46 47 |
# File 'lib/showroom/models/search/suggestion.rb', line 45 def load self.class.complete_model_class.find(loadable_identifier) end |
#loadable_identifier ⇒ String
Returns the identifier used to fetch the full record (defaults to the handle attribute). Override in subclasses when the identifier differs.
33 34 35 |
# File 'lib/showroom/models/search/suggestion.rb', line 33 def loadable_identifier @attrs['handle'] end |