Class: MiddlewareAutocomplete::Base
- Inherits:
-
Object
- Object
- MiddlewareAutocomplete::Base
- Defined in:
- lib/middleware_autocomplete/base.rb
Class Attribute Summary collapse
-
.content_type ⇒ Object
Content type symbol, e.g.
-
.namespace ⇒ Object
Returns the value of attribute namespace.
-
.path ⇒ Object
Path without namespace.
-
.route_name ⇒ Object
Route name to access Autocomplete search, e.g.
-
.search_key ⇒ Object
Returns the value of attribute search_key.
Class Method Summary collapse
- .call(env) ⇒ Object
-
.content_type_string ⇒ Object
Content type string, e.g.
-
.perform(params) ⇒ Object
Calls user defined method to return results Wraps this method with AR with_connection to prevent connection leaks.
-
.route ⇒ Object
Full path to the Autocomplete class.
-
.search(params) ⇒ Object
Returns search results for autocompletition Result should be in the same format that your content_type Should be defined by user.
- .use_with_connection ⇒ Object
Class Attribute Details
.content_type ⇒ Object
Content type symbol, e.g. :json, :xml
58 59 60 |
# File 'lib/middleware_autocomplete/base.rb', line 58 def content_type @content_type end |
.namespace ⇒ Object
Returns the value of attribute namespace.
4 5 6 |
# File 'lib/middleware_autocomplete/base.rb', line 4 def namespace @namespace end |
.path ⇒ Object
Path without namespace
33 34 35 |
# File 'lib/middleware_autocomplete/base.rb', line 33 def path @path end |
.route_name ⇒ Object
Route name to access Autocomplete search, e.g. autocomplete_posts_path
38 39 40 |
# File 'lib/middleware_autocomplete/base.rb', line 38 def route_name @route_name end |
.search_key ⇒ Object
Returns the value of attribute search_key.
4 5 6 |
# File 'lib/middleware_autocomplete/base.rb', line 4 def search_key @search_key end |
Class Method Details
.call(env) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/middleware_autocomplete/base.rb', line 20 def call(env) ActiveSupport::Notifications.instrument 'request.middleware_autocomplete' do result = perform(Rack::Request.new(env).params) [200, { 'Content-Type' => content_type_string }, [result]] end end |
.content_type_string ⇒ Object
Content type string, e.g. ‘application/json’, ‘application/xml’
63 64 65 |
# File 'lib/middleware_autocomplete/base.rb', line 63 def content_type_string Mime::Type.lookup_by_extension(content_type).to_s end |
.perform(params) ⇒ Object
Calls user defined method to return results Wraps this method with AR with_connection to prevent connection leaks
Attributes
-
params
- Params hash passed to request
12 13 14 15 16 17 18 |
# File 'lib/middleware_autocomplete/base.rb', line 12 def perform(params) if use_with_connection with_connection { search(params) } else search(params) end end |
.route ⇒ Object
Full path to the Autocomplete class
28 29 30 |
# File 'lib/middleware_autocomplete/base.rb', line 28 def route [namespace, path].reject(&:blank?).join('/').prepend('/') end |
.search(params) ⇒ Object
Returns search results for autocompletition Result should be in the same format that your content_type Should be defined by user
53 54 55 |
# File 'lib/middleware_autocomplete/base.rb', line 53 def search(params) raise NotImplementedError end |
.use_with_connection ⇒ Object
46 47 48 |
# File 'lib/middleware_autocomplete/base.rb', line 46 def use_with_connection @use_with_connection || MiddlewareAutocomplete.use_with_connection end |