Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ViewServer
- protocol CouchDBQueryServerProtocol
- # commands is a class method defined in a module that ViewServer includes
- commands do
- # "on" performs erlang style pattern matching on an arguments
- on :reset do
- reset
- return true
- end
- on :add_fun do |func|
- # add_map_functions is a class method on ViewServer
- add_map_function(func)
- end
- on :reduce do |func, kv_pairs|
- # reduce is a instance method on a ViewServer object
- new.reduce(func, kv_pairs)
- end
- on :ddoc do
- # i am now switching my "worker" object to a different class.
- switch_state DesignDoc do
- class DesignDoc
- # i would like to not have to call "protocol" here.
- commands do
- on :new do |doc_name, doc|
- #this gets successfully called on the correct command string
- # but "@protocol" isn't set.
- new_doc doc_name, doc
- end
- on :shows do |show_func, doc, req|
- execute show_func, doc, req do |result|
- stop_with result if result.respond_to? :first and result.first == "error"
- stop_with ["resp",result.is_a?(String) ? {"body" => result} : result]
- end
- end
- end
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment