Guest User

Untitled

a guest
Jun 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. class ViewServer
  2.  
  3. protocol CouchDBQueryServerProtocol
  4.  
  5. # commands is a class method defined in a module that ViewServer includes
  6. commands do
  7.  
  8. # "on" performs erlang style pattern matching on an arguments
  9. on :reset do
  10. reset
  11. return true
  12. end
  13.  
  14. on :add_fun do |func|
  15. # add_map_functions is a class method on ViewServer
  16. add_map_function(func)
  17. end
  18.  
  19. on :reduce do |func, kv_pairs|
  20. # reduce is a instance method on a ViewServer object
  21. new.reduce(func, kv_pairs)
  22. end
  23.  
  24. on :ddoc do
  25. # i am now switching my "worker" object to a different class.
  26. switch_state DesignDoc do
  27. class DesignDoc
  28. # i would like to not have to call "protocol" here.
  29.  
  30. commands do
  31.  
  32. on :new do |doc_name, doc|
  33. #this gets successfully called on the correct command string
  34. # but "@protocol" isn't set.
  35. new_doc doc_name, doc
  36. end
  37.  
  38. on :shows do |show_func, doc, req|
  39. execute show_func, doc, req do |result|
  40. stop_with result if result.respond_to? :first and result.first == "error"
  41. stop_with ["resp",result.is_a?(String) ? {"body" => result} : result]
  42. end
  43. end
  44.  
  45. end
  46. end
  47. end
  48. end
  49. end
  50. end
Add Comment
Please, Sign In to add comment