Sha256: da7f2ca1bbdeffb5bb054e82930b6e71f0927685fd7f4e0b7d0ca118e4c2673e

Contents?: true

Size: 988 Bytes

Versions: 2

Compression:

Stored size: 988 Bytes

Contents

module Bootstrap3AutocompleteInput
	module Orm
		module MongoMapper
			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

			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
		end	
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bootstrap3_autocomplete_input-0.2.3 lib/bootstrap3_autocomplete_input/orm/mongo_mapper.rb
bootstrap3_autocomplete_input-0.2.1 lib/bootstrap3_autocomplete_input/orm/mongo_mapper.rb