Class: MiddlewareAutocomplete::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/middleware_autocomplete/base.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.content_typeObject

Content type symbol, e.g. :json, :xml



51
52
53
# File 'lib/middleware_autocomplete/base.rb', line 51

def content_type
  @content_type
end

.namespaceObject

Returns the value of attribute namespace.



4
5
6
# File 'lib/middleware_autocomplete/base.rb', line 4

def namespace
  @namespace
end

.pathObject

Path without namespace



26
27
28
# File 'lib/middleware_autocomplete/base.rb', line 26

def path
  @path
end

.route_nameObject

Route name to access Autocomplete search, e.g. autocomplete_posts_path



31
32
33
# File 'lib/middleware_autocomplete/base.rb', line 31

def route_name
  @route_name
end

.search_keyObject

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

.content_type_stringObject

Content type string, e.g. ‘application/json’, ‘application/xml’



56
57
58
# File 'lib/middleware_autocomplete/base.rb', line 56

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

.routeObject

Full path to the Autocomplete class



21
22
23
# File 'lib/middleware_autocomplete/base.rb', line 21

def route
  [namespace, path].join('/')
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

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/middleware_autocomplete/base.rb', line 46

def search(params)
  raise NotImplementedError
end

.use_with_connectionObject



39
40
41
# File 'lib/middleware_autocomplete/base.rb', line 39

def use_with_connection
  @use_with_connection || MiddlewareAutocomplete.use_with_connection
end