rack-autocrud 0.1.17 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -12
- data/lib/rack/autocrud.rb +10 -10
- metadata +1 -1
data/README.md
CHANGED
@@ -125,22 +125,23 @@ CRUD Processing Hooks
|
|
125
125
|
|
126
126
|
There are some basic processing hooks you can define in your endpoint:
|
127
127
|
|
128
|
-
| Hook
|
129
|
-
|
|
130
|
-
| pre_create(request,params) | Called before the record is created |
|
131
|
-
| post_create(request,obj) | Called after the record is saved, if it was saved successfully |
|
132
|
-
| pre_retrieve(request,params) | Called before the record is fetched |
|
133
|
-
| post_retrieve(request,obj) | Called after the record is fetched |
|
134
|
-
| pre_update(request,params) | Called before the record is updated |
|
135
|
-
| post_update(request,params) | Called after the record is updated, if it was saved successfully |
|
136
|
-
| pre_destroy(request,params) | Called before the record is destroyed |
|
137
|
-
| post_destroy(request,obj) | Called after the record is destroyed |
|
138
|
-
| pre_collect(request,params) | Called before the record is collected |
|
139
|
-
| post_collect(request,collection) | Called after the record is collected |
|
128
|
+
| Hook | Description |
|
129
|
+
| ----------------------------------------- | ---------------------------------------------------------------- |
|
130
|
+
| pre_create(model,request,params) | Called before the record is created |
|
131
|
+
| post_create(model,request,obj) | Called after the record is saved, if it was saved successfully |
|
132
|
+
| pre_retrieve(model,request,params) | Called before the record is fetched |
|
133
|
+
| post_retrieve(model,request,obj) | Called after the record is fetched |
|
134
|
+
| pre_update(model,request,params) | Called before the record is updated |
|
135
|
+
| post_update(model,request,params) | Called after the record is updated, if it was saved successfully |
|
136
|
+
| pre_destroy(model,request,params) | Called before the record is destroyed |
|
137
|
+
| post_destroy(model,request,obj) | Called after the record is destroyed |
|
138
|
+
| pre_collect(model,request,params) | Called before the record is collected |
|
139
|
+
| post_collect(model,request,collection) | Called after the record is collected |
|
140
140
|
|
141
141
|
|
142
142
|
Parameters:
|
143
143
|
|
144
|
+
* *model* is the model class for the endpoint
|
144
145
|
* *request* is the current request object
|
145
146
|
* *obj* is the ORM object corresponding to the record in question
|
146
147
|
* *collection* is the collection returned by the ORM
|
data/lib/rack/autocrud.rb
CHANGED
@@ -97,7 +97,7 @@ module Rack
|
|
97
97
|
|
98
98
|
# Call the pre-create hook
|
99
99
|
if self.respond_to?(:pre_collect)
|
100
|
-
ret = pre_collect(request,params)
|
100
|
+
ret = pre_collect(model,request,params)
|
101
101
|
return ret unless ret.nil?
|
102
102
|
end
|
103
103
|
|
@@ -106,7 +106,7 @@ module Rack
|
|
106
106
|
|
107
107
|
# Call the post-collect hook
|
108
108
|
if self.respond_to?(:post_collect)
|
109
|
-
ret = post_collect(request,collection)
|
109
|
+
ret = post_collect(model,request,collection)
|
110
110
|
return ret unless ret.nil?
|
111
111
|
end
|
112
112
|
|
@@ -116,7 +116,7 @@ module Rack
|
|
116
116
|
post '/' do
|
117
117
|
# Call the pre-create hook
|
118
118
|
if self.respond_to?(:pre_create)
|
119
|
-
ret = pre_create(request,params)
|
119
|
+
ret = pre_create(model,request,params)
|
120
120
|
return ret unless ret.nil?
|
121
121
|
end
|
122
122
|
|
@@ -134,7 +134,7 @@ module Rack
|
|
134
134
|
|
135
135
|
# Call the post-create hook
|
136
136
|
if self.respond_to?(:post_create)
|
137
|
-
ret = post_create(request,obj)
|
137
|
+
ret = post_create(model,request,obj)
|
138
138
|
return ret unless ret.nil?
|
139
139
|
end
|
140
140
|
|
@@ -144,7 +144,7 @@ module Rack
|
|
144
144
|
get '/:id' do
|
145
145
|
# Call the pre-retrieve hook
|
146
146
|
if self.respond_to?(:pre_retrieve)
|
147
|
-
ret = pre_retrieve(request,params)
|
147
|
+
ret = pre_retrieve(model,request,params)
|
148
148
|
return ret unless ret.nil?
|
149
149
|
end
|
150
150
|
|
@@ -152,7 +152,7 @@ module Rack
|
|
152
152
|
|
153
153
|
# Call the post-retrieve hook
|
154
154
|
if self.respond_to?(:post_retrieve)
|
155
|
-
ret = post_retrieve(request,obj)
|
155
|
+
ret = post_retrieve(model,request,obj)
|
156
156
|
return ret unless ret.nil?
|
157
157
|
end
|
158
158
|
|
@@ -162,7 +162,7 @@ module Rack
|
|
162
162
|
put '/:id' do
|
163
163
|
# Call the pre-update hook
|
164
164
|
if self.respond_to?(:pre_update)
|
165
|
-
ret = pre_update(request,params)
|
165
|
+
ret = pre_update(model,request,params)
|
166
166
|
return ret unless ret.nil?
|
167
167
|
end
|
168
168
|
|
@@ -179,7 +179,7 @@ module Rack
|
|
179
179
|
|
180
180
|
# Call the post-update hook
|
181
181
|
if self.respond_to?(:post_update)
|
182
|
-
ret = post_update(request,params)
|
182
|
+
ret = post_update(model,request,params)
|
183
183
|
return ret unless ret.nil?
|
184
184
|
end
|
185
185
|
|
@@ -189,7 +189,7 @@ module Rack
|
|
189
189
|
delete '/:id' do
|
190
190
|
# Call the pre-destroy hook
|
191
191
|
if self.respond_to?(:pre_destroy)
|
192
|
-
ret = pre_destroy(request,params)
|
192
|
+
ret = pre_destroy(model,request,params)
|
193
193
|
return ret unless ret.nil?
|
194
194
|
end
|
195
195
|
|
@@ -198,7 +198,7 @@ module Rack
|
|
198
198
|
|
199
199
|
# Call the post-destroy hook
|
200
200
|
if self.respond_to?(:post_destroy)
|
201
|
-
ret = post_destroy(request,obj)
|
201
|
+
ret = post_destroy(model,request,obj)
|
202
202
|
return ret unless ret.nil?
|
203
203
|
end
|
204
204
|
|