Class: Udongo::Search::ResultObjects::Base
- Inherits:
-
Object
- Object
- Udongo::Search::ResultObjects::Base
- Defined in:
- lib/udongo/search/result_objects/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#search_context ⇒ Object
readonly
Returns the value of attribute search_context.
Instance Method Summary collapse
-
#build_html ⇒ Object
Typically, an autocomplete requires 3 things:.
- #hidden? ⇒ Boolean
-
#initialize(index, search_context: nil) ⇒ Base
constructor
A new instance of Base.
- #label ⇒ Object
- #locals ⇒ Object
- #partial ⇒ Object
- #partial_path ⇒ Object
- #partial_target ⇒ Object
- #unpublished? ⇒ Boolean
- #url ⇒ Object
Constructor Details
#initialize(index, search_context: nil) ⇒ Base
Returns a new instance of Base.
12 13 14 15 |
# File 'lib/udongo/search/result_objects/base.rb', line 12 def initialize(index, search_context: nil) @index = index @search_context = search_context end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
8 9 10 |
# File 'lib/udongo/search/result_objects/base.rb', line 8 def index @index end |
#search_context ⇒ Object (readonly)
Returns the value of attribute search_context.
8 9 10 |
# File 'lib/udongo/search/result_objects/base.rb', line 8 def search_context @search_context end |
Instance Method Details
#build_html ⇒ Object
Typically, an autocomplete requires 3 things:
-
A title indicating a resource name. Examples: Page#title, Product#name,…
-
A truncated summary providing a glimpse of the resource’s contents. Examples: Page#subtitle, Product#description,…
-
A link to the resource. Examples: edit_backend_page_path(37), product_path(37),…
However, this seems very restrictive to me. If I narrow down the data a dev can use in an autocomplete, it severely reduces options he/she has in how the autocomplete results look like. Think of autocompletes in a shop that require images or prices to be included in their result bodies.
This is why I chose to let ApplicationController.render work around the problem by letting the dev decide how the row should look.
34 35 36 |
# File 'lib/udongo/search/result_objects/base.rb', line 34 def build_html ApplicationController.render(partial: partial, locals: locals) end |
#hidden? ⇒ Boolean
38 39 40 |
# File 'lib/udongo/search/result_objects/base.rb', line 38 def hidden? searchable.respond_to?(:visible?) && searchable.hidden? end |
#label ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/udongo/search/result_objects/base.rb', line 42 def label if index.name.include?('flexible_content') id = index.name.split(':')[1].to_i return ContentText.find(id).content end searchable.send(index.name) end |
#locals ⇒ Object
51 52 53 |
# File 'lib/udongo/search/result_objects/base.rb', line 51 def locals { "#{partial_target}": index.searchable, index: index } end |
#partial ⇒ Object
55 56 57 |
# File 'lib/udongo/search/result_objects/base.rb', line 55 def partial "#{partial_path}/#{partial_target}" end |
#partial_path ⇒ Object
59 60 61 |
# File 'lib/udongo/search/result_objects/base.rb', line 59 def partial_path "#{search_context.namespace.to_s.underscore}/search" end |
#partial_target ⇒ Object
63 64 65 |
# File 'lib/udongo/search/result_objects/base.rb', line 63 def partial_target index.searchable_type.underscore end |
#unpublished? ⇒ Boolean
67 68 69 |
# File 'lib/udongo/search/result_objects/base.rb', line 67 def unpublished? searchable.respond_to?(:published?) && searchable.unpublished? end |
#url ⇒ Object
71 72 |
# File 'lib/udongo/search/result_objects/base.rb', line 71 def url end |