lib/rails4-autocomplete/orm/mongoid.rb in rails4-autocomplete-1.0.7 vs lib/rails4-autocomplete/orm/mongoid.rb in rails4-autocomplete-1.1.0
- old
+ new
@@ -15,20 +15,30 @@
def get_autocomplete_items(parameters)
model = parameters[:model]
method = parameters[:method]
options = parameters[:options]
+ scopes = options[:scopes]
is_full_search = options[:full]
term = parameters[:term]
limit = get_autocomplete_limit(options)
order = get_autocomplete_order(method, options)
if is_full_search
search = '.*' + Regexp.escape(term) + '.*'
else
search = '^' + Regexp.escape(term)
end
- items = model.where(method.to_sym => /#{search}/i).limit(limit).order_by(order)
+
+ items = model.where(method.to_sym => /#{search}/i).limit(limit).order_by(order)
+
+ case scopes
+ when Symbol then
+ items = items.send(scopes)
+ when Array then
+ scopes.each { |scope| items = items.send(scope) } unless scopes.empty?
+ end
+ items
end
end
end
end