Class: Gizmo::Search
- Inherits:
-
BaseOperation
- Object
- BaseOperation
- Gizmo::Search
- Defined in:
- lib/gizmo/search.rb
Instance Attribute Summary
Attributes inherited from BaseOperation
Instance Method Summary collapse
-
#call(criteria, params = {}) ⇒ Gizmo::Response
Search for items.
Methods inherited from BaseOperation
#create_response, #default_status, #initialize, #set_response_headers
Constructor Details
This class inherits a constructor from Gizmo::BaseOperation
Instance Method Details
#call(criteria, params = {}) ⇒ Gizmo::Response
Search for items.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gizmo/search.rb', line 16 def call(criteria, params={}) response = create_response if block_given? response.data = yield criteria, params else term = params[:term] query = params[:query] num_items = (params[:num_items] || 10).to_i num_items = 10 if num_items > 100 || num_items < 1 fuzzy = !!((params[:fuzzy] || "") =~ /true/i) if fuzzy query = /#{query}/i end response.data = criteria.where(term => query).limit(num_items) end response end |