Module: Sinatra::RbbtFinder
- Defined in:
- lib/rbbt/workflow/rest/finder.rb
Defined Under Namespace
Modules: Helpers
Class Method Summary collapse
Class Method Details
.registered(app) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rbbt/workflow/rest/finder.rb', line 35 def self.registered(app) app.helpers RbbtFinder::Helpers app.get '/find' do return workflow_render('find.haml') if params[:term].nil? Log.debug "find: #{params.inspect}" term = params[:term] sorted_results = finder_find(term) raise "No finder defined" if app.finder.nil? if request.xhr? content_type "application/json" sorted_results.to_json else i = sorted_results.first raise "Term not recognized: #{ term }" if i.nil? redirect_to_entity(i[:code], i[:format], i[:namespace]) end end app.post '/find' do term = params[:term] if term =~ /(.*) \[(.*)\]$/ term = $1 namespace, format = $2.split(":") format, namespace = namespace, nil if format.nil? redirect_to_entity(term, format, namespace) else sorted_results = finder_find(term) i = sorted_results.first raise "Term not recognized: #{ term }" if i.nil? redirect_to_entity(i[:code], i[:format], i[:namespace]) end end end |