Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+ rewrite prototypes

  • Loading branch information...
commit 769a3ef0c3bae764a07077d6212e8b7e52b0f7b5 1 parent c7f154e
@floere authored
Showing with 44 additions and 8 deletions.
  1. +44 −8 server/prototypes/active_record/server/app.rb
View
52 server/prototypes/active_record/server/app.rb
@@ -14,22 +14,58 @@ class ExternalDataSearch < Sinatra::Base
include Picky
extend Sinatra::IndexActions
- data = Index.new :models do
- category :id
- category :name
- category :surname
+ def initialize
+ at_exit { data.dump }
end
+
+ def data
+ @data ||= Index.new :models do
+ category :id
+ category :name
+ category :surname
+ end
+ end
+
+ def finder
+ @finder ||= Search.new data
+ end
+
post %r{\A/update\z} do # PUT?
hash = JSON.parse params['data']
data.replace_from hash
puts "UPDATING from #{hash}"
end
- at_exit { data.dump }
- models = Search.new data
get %r{\A/search\z} do
- results = models.search params['query'], params['ids'] || 20, params['offset'] || 0
+ results = finder.search params['query'], params['ids'] || 20, params['offset'] || 0
results.to_json
end
-end
+end
+
+# Was this code below, but people don't get contexts etc.
+#
+# class ExternalDataSearch < Sinatra::Base
+#
+# include Picky
+# extend Sinatra::IndexActions
+#
+# data = Index.new :models do
+# category :id
+# category :name
+# category :surname
+# end
+# post %r{\A/update\z} do # PUT?
+# hash = JSON.parse params['data']
+# data.replace_from hash
+# puts "UPDATING from #{hash}"
+# end
+# at_exit { data.dump }
+#
+# models = Search.new data
+# get %r{\A/search\z} do
+# results = models.search params['query'], params['ids'] || 20, params['offset'] || 0
+# results.to_json
+# end
+#
+# end
Please sign in to comment.
Something went wrong with that request. Please try again.