Module: BootstrapAutocompleteInput::Orm::MongoMapper

Defined in:
lib/bootstrap_autocomplete_input/orm/mongo_mapper.rb

Instance Method Summary collapse

Instance Method Details

#get_autocomplete_items(parameters) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bootstrap_autocomplete_input/orm/mongo_mapper.rb', line 16

def get_autocomplete_items(parameters)
     model          = parameters[:model]
     method         = parameters[:method]
     options        = parameters[:options]
     is_full_search = options[:full]
     term           = parameters[:term]
     limit          = autocomplete_option_limit(options)
     order          = get_autocomplete_order(method, options)

     search = (is_full_search ? '.*' : '^') + term + '.*'
	items  = model.where(method.to_sym => /#{search}/i).limit(limit).sort(order)
end

#get_autocomplete_order(method, options, model = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/bootstrap_autocomplete_input/orm/mongo_mapper.rb', line 4

def get_autocomplete_order(method, options, model=nil)
     order = options[:order]
     if order
       order.split(',').collect do |fields|
         sfields = fields.split
         [sfields[0].downcase.to_sym, sfields[1].downcase.to_sym]
       end
     else
       [[method.to_sym, :asc]]
     end
end