wurst 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wurst/resource.rb +15 -8
- data/lib/wurst/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfe6de8e5bf7b64113eddef6e542b3c02ab699e9
|
4
|
+
data.tar.gz: 2c37731cec40c66e0abc3a9f4d25a206436e93fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04b1d6e584f8e4179c1d23cc2c63a0a718c33130456972474a9d78c72120b538587ffe3bb4480117626346fd617c7cc4107a3c97822123fa4080c45c3c720d96
|
7
|
+
data.tar.gz: 1c0207c4f73a50f0f377e8819f0e32933fd9ae2e326d7b51359374d770bce0c43c0a38ba4b3acce2d53ddce57bf8d5be3aca796cb1f65c1c5affb0c19faad079
|
data/lib/wurst/resource.rb
CHANGED
@@ -46,11 +46,10 @@ module ZWResources
|
|
46
46
|
Tilt::ERBTemplate.new{@@models_js_template}.render
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
base.send :get, file.split('/').last do
|
49
|
+
%w(handlebars-v1.3.0.js ember.js ember-data.js).each do |filename|
|
50
|
+
base.send :get, "/#{filename}" do
|
52
51
|
content_type :js, :charset => 'utf-8'
|
53
|
-
|
52
|
+
File.read File.join(File.dirname(File.expand_path(__FILE__)), "../assets/#{filename}")
|
54
53
|
end
|
55
54
|
end
|
56
55
|
end
|
@@ -70,6 +69,14 @@ module ZWResources
|
|
70
69
|
puts "***"
|
71
70
|
puts router.routes.inspect
|
72
71
|
|
72
|
+
# Parse JSON payload
|
73
|
+
# http://stackoverflow.com/a/17049683
|
74
|
+
before do
|
75
|
+
request.body.rewind
|
76
|
+
request_body = request.body.read
|
77
|
+
@request_payload = JSON.parse(request_body, :symbolize_names => true) unless request_body.empty?
|
78
|
+
end
|
79
|
+
|
73
80
|
# Find
|
74
81
|
get "/#{model_name_string}/:id" do |id|
|
75
82
|
content_type :json, :charset => 'utf-8'
|
@@ -94,11 +101,11 @@ module ZWResources
|
|
94
101
|
put "/#{model_name_string}/:id" do |id|
|
95
102
|
content_type :json, :charset => 'utf-8'
|
96
103
|
if router.has_route? :update
|
97
|
-
{post: router.update(id,
|
104
|
+
{post: router.update(id, @request_payload[:post])}.to_json
|
98
105
|
else
|
99
106
|
param_names = model.properties.select{ |prop| prop.class != DataMapper::Property::Serial }.map{ |prop| prop.name }
|
100
107
|
m = model.get(id)
|
101
|
-
m.update(
|
108
|
+
m.update(@request_payload[:post].select{ |k,v| param_names.include? k.to_sym })
|
102
109
|
{post: m}.to_json
|
103
110
|
end
|
104
111
|
end
|
@@ -107,10 +114,10 @@ module ZWResources
|
|
107
114
|
post "/#{model_name_string}" do
|
108
115
|
content_type :json, :charset => 'utf-8'
|
109
116
|
if router.has_route? :create
|
110
|
-
{post: router.create(
|
117
|
+
{post: router.create(@request_payload[:post])}.to_json
|
111
118
|
else
|
112
119
|
param_names = model.properties.select{ |prop| prop.class != DataMapper::Property::Serial }.map{ |prop| prop.name }
|
113
|
-
m = model.create(
|
120
|
+
m = model.create(@request_payload[:post].select{ |k,v| param_names.include? k.to_sym })
|
114
121
|
{post: m}.to_json
|
115
122
|
end
|
116
123
|
end
|
data/lib/wurst/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wurst
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cdn64
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|