module PrixFixeModel
Public Class Methods
included(base)
click to toggle source
# File lib/prix_fixe_model.rb, line 22 def self.included(base) base.class_eval do after_create :add_to_search before_update :reindex before_destroy :remove_from_search end end
Public Instance Methods
add_to_search()
click to toggle source
# File lib/prix_fixe_model.rb, line 37 def add_to_search json_data = self.dump_data post_data(json_data) end
dump_data()
click to toggle source
# File lib/prix_fixe_model.rb, line 4 def dump_data hash = {} hash["Key"] = self[index[0]] tokens = {} attrs_to_include.each do |attr| tokens[attr] = self.send(attr).to_s end hash["Tokens"] = tokens hash.to_json end
post_data(data)
click to toggle source
# File lib/prix_fixe_model.rb, line 30 def post_data(data) uri = URI(PRIX_FIXE[:server] + "/putall") # This doesn't retry if it fails, and it also blocked. This should probably # support resque or delayedjob if it's installed response = Net::HTTP.post_form(uri, {"data" => data}) end
reindex()
click to toggle source
# File lib/prix_fixe_model.rb, line 42 def reindex old_data = self.remove_data new_data = self.dump_data post_data("#{old_data}\n#{new_data}") end
remove_data()
click to toggle source
# File lib/prix_fixe_model.rb, line 15 def remove_data { "Key" => self.send("#{index[0]}_was"), "Tokens" => nil }.to_json end
remove_from_search()
click to toggle source
# File lib/prix_fixe_model.rb, line 48 def remove_from_search post_data(self.remove_data) end