rack-autocrud 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +2 -1
- data/lib/rack/autocrud.rb +2 -4
- metadata +2 -2
data/README.md
CHANGED
@@ -85,6 +85,7 @@ module Endpoints
|
|
85
85
|
get '/'
|
86
86
|
Models::Person.all.to_json
|
87
87
|
end
|
88
|
+
end
|
88
89
|
end
|
89
90
|
```
|
90
91
|
|
@@ -98,7 +99,7 @@ There are some basic processing hooks you can define in your endpoint:
|
|
98
99
|
|
99
100
|
| Hook | Description |
|
100
101
|
| ------------------------------ | ---------------------------------------------------------------- |
|
101
|
-
| pre_create(env,request,obj) | Called
|
102
|
+
| pre_create(env,request,obj) | Called before the record is created |
|
102
103
|
| post_create(env,request,obj) | Called after the record is saved, if it was saved successfully |
|
103
104
|
| pre_retrieve(env,request) | Called before the record is fetched |
|
104
105
|
| post_retrieve(env,request,obj) | Called after the record is fetched |
|
data/lib/rack/autocrud.rb
CHANGED
@@ -61,16 +61,14 @@ module Rack
|
|
61
61
|
end
|
62
62
|
|
63
63
|
post '/' do
|
64
|
-
obj = model.new(JSON.parse(request.body.read))
|
65
|
-
|
66
64
|
# Call the pre-create hook
|
67
65
|
if self.respond_to?(:pre_create)
|
68
66
|
ret = pre_create(env,request,obj)
|
69
67
|
return ret unless ret.nil?
|
70
68
|
end
|
71
69
|
|
72
|
-
obj.
|
73
|
-
halt [402, '{ "error": "Failed to save ' + endpoint + '" }'] unless obj.saved?
|
70
|
+
obj = model.create(JSON.parse(request.body.read))
|
71
|
+
halt [402, '{ "error": "Failed to save ' + endpoint + '" }'] unless obj && obj.saved?
|
74
72
|
|
75
73
|
# Call the post-create hook
|
76
74
|
if self.respond_to?(:post_create)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-autocrud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|