Sha256: d9165bb344159e02688382548804e08a17218e7b43ee1808b33988b4facc622e

Contents?: true

Size: 989 Bytes

Versions: 4

Compression:

Stored size: 989 Bytes

Contents

module RailsJQueryAutocomplete
	module Orm
		module MongoMapper
			def mongo_mapper_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 mongo_mapper_get_autocomplete_items(parameters)
        model          = parameters[:model]
        method         = parameters[:method]
        options        = parameters[:options]
        is_full_search = options[:full]
        term           = parameters[:term]
        limit          = get_autocomplete_limit(options)
        order          = mongo_mapper_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

4 entries across 4 versions & 1 rubygems

Version Path
rails-jquery-autocomplete-1.0.3 lib/rails-jquery-autocomplete/orm/mongo_mapper.rb
rails-jquery-autocomplete-1.0.2 lib/rails-jquery-autocomplete/orm/mongo_mapper.rb
rails-jquery-autocomplete-1.0.1 lib/rails-jquery-autocomplete/orm/mongo_mapper.rb
rails-jquery-autocomplete-1.0.0 lib/rails-jquery-autocomplete/orm/mongo_mapper.rb