Module: ClientSideAutocomplete::Autocomplete
- Included in:
- ActionController::Base
- Defined in:
- lib/client_side_autocomplete/autocomplete.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#get_autocomplete_limit(options) ⇒ Object
Returns a limit that will be used on the query.
-
#get_object(model_sym) ⇒ Object
Returns parameter model_sym as a constant.
-
#json_for_autocomplete(items, method, extra_data = []) ⇒ Object
Returns a hash with three keys actually used by the Autocomplete jQuery-ui Can be overriden to show whatever you like Hash also includes a key/value pair for each method in extra_data.
Class Method Details
.included(target) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/client_side_autocomplete/autocomplete.rb', line 3 def self.included(target) target.extend ClientSideAutocomplete::Autocomplete::ClassMethods if defined?(Mongoid::Document) target.send :include, ClientSideAutocomplete::Orm::Mongoid elsif defined?(MongoMapper::Document) target.send :include, ClientSideAutocomplete::Orm::MongoMapper else target.send :include, ClientSideAutocomplete::Orm::ActiveRecord end end |
Instance Method Details
#get_autocomplete_limit(options) ⇒ Object
Returns a limit that will be used on the query
66 67 68 |
# File 'lib/client_side_autocomplete/autocomplete.rb', line 66 def get_autocomplete_limit() [:limit] ||= 10 end |
#get_object(model_sym) ⇒ Object
Returns parameter model_sym as a constant
get_object(:actor)
# returns a Actor constant supposing it is already defined
75 76 77 |
# File 'lib/client_side_autocomplete/autocomplete.rb', line 75 def get_object(model_sym) object = model_sym.to_s.camelize.constantize end |
#json_for_autocomplete(items, method, extra_data = []) ⇒ Object
Returns a hash with three keys actually used by the Autocomplete jQuery-ui Can be overriden to show whatever you like Hash also includes a key/value pair for each method in extra_data
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/client_side_autocomplete/autocomplete.rb', line 84 def json_for_autocomplete(items, method, extra_data=[]) items.collect do |item| hash = {"id" => item.id.to_s, "label" => item.send(method), "value" => item.send(method)} extra_data.each do |datum| hash[datum] = item.send(datum) end if extra_data # TODO: Come back to remove this if clause when test suite is better hash end end |