Module: Redis::Autosuggest::ClassMethods

Defined in:
lib/redis/autosuggest/rails/sources.rb

Instance Method Summary collapse

Instance Method Details

#autosuggest(column, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/redis/autosuggest/rails/sources.rb', line 6

def autosuggest(column, options={})
hash = Redis::Autosuggest.rails_sources[self]
if hash.nil?
  Redis::Autosuggest.rails_sources[self] = { column => options }
else
  hash[column] = options
end

# Hook onto rails callbacks to update autosuggest db if a source is modified
class_eval "  after_create :add_to_autosuggest\n  def add_to_autosuggest\n    Redis::Autosuggest::SuggestRails.add_to_autosuggest(self)\n  end\n\n  after_update :check_if_changed\n  def check_if_changed\n    Redis::Autosuggest::SuggestRails.check_if_changed(self)\n  end\n\n  before_destroy :remove_from_autosuggest\n  def remove_from_autosuggest\n    Redis::Autosuggest::SuggestRails.remove_from_autosuggest(self)\n  end\n  HERE\nend\n"